From 578fa72a9a8fd54595134aeee7636f37809f6b76 Mon Sep 17 00:00:00 2001 From: jose luis <2064537+sosan@users.noreply.github.com> Date: Wed, 24 Jan 2024 23:41:01 +0100 Subject: [PATCH 1/3] fix issue 1793 * fix issue 1793 https://github.com/kubernetes/kompose/issues/1793 *add tests Signed-off-by: jose luis <2064537+sosan@users.noreply.github.com> formated k8utils_test.go Signed-off-by: jose luis <2064537+sosan@users.noreply.github.com> labels formatted as name"-"envName to match fixtures when performing the gitHub action Signed-off-by: jose luis <2064537+sosan@users.noreply.github.com> removed this piece code because apply it later, and it is redundant Signed-off-by: jose luis <2064537+sosan@users.noreply.github.com> Refactor test in k8sutils_test.go to extract the last 63 characters. This addresses the impact of the removed code that previously truncated the input with if len(envName) > 63 { envName = envName[len(envName)-63:] } Signed-off-by: jose luis <2064537+sosan@users.noreply.github.com> changed to name function to getUsableNameEnvFile Signed-off-by: jose luis <2064537+sosan@users.noreply.github.com> fix issue 1793 * fix issue 1793 https://github.com/kubernetes/kompose/issues/1793 *add tests Signed-off-by: jose luis <2064537+sosan@users.noreply.github.com> labels formatted as name"-"envName to match fixtures when performing the gitHub action Signed-off-by: jose luis <2064537+sosan@users.noreply.github.com> changed to name function to getUsableNameEnvFile Signed-off-by: jose luis <2064537+sosan@users.noreply.github.com> --- pkg/transformer/kubernetes/k8sutils.go | 23 ++++++++++++++++----- pkg/transformer/kubernetes/k8sutils_test.go | 15 +++++++++++--- pkg/transformer/kubernetes/kubernetes.go | 4 ++-- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/pkg/transformer/kubernetes/k8sutils.go b/pkg/transformer/kubernetes/k8sutils.go index 49510ec8..b1f06834 100644 --- a/pkg/transformer/kubernetes/k8sutils.go +++ b/pkg/transformer/kubernetes/k8sutils.go @@ -891,17 +891,30 @@ func GetContentFromFile(file string) (string, error) { } // FormatEnvName format env name -func FormatEnvName(name string) string { +func FormatEnvName(name string, serviceName string) string { envName := strings.Trim(name, "./") // only take string after the last slash only if the string contains a slash if strings.Contains(envName, "/") { envName = envName[strings.LastIndex(envName, "/")+1:] } - // take only last chars: The ones after 63th index - if len(envName) > 63 { - envName = envName[len(envName)-63:] + + envName = strings.Replace(envName, ".", "-", -1) + envName = getUsableNameEnvFile(envName, serviceName) + return envName +} + +// getUsableNameEnvFile checks and adjusts the environment file name to make it usable. +// If the first character of envName is a hyphen "-", it is concatenated with nameService. +// If the length of envName is greater than 63, it is truncated to 63 characters. +// Returns the adjusted environment file name. +func getUsableNameEnvFile(envName string, serviceName string) string { + if string(envName[0]) == "-" { // -env-local.... + envName = fmt.Sprintf("%s%s", serviceName, envName) } - return strings.Replace(envName, ".", "-", -1) + if len(envName) > 63 { + envName = envName[0:63] + } + return envName } // FormatFileName format file name diff --git a/pkg/transformer/kubernetes/k8sutils_test.go b/pkg/transformer/kubernetes/k8sutils_test.go index 3be2d53c..637d7f2b 100644 --- a/pkg/transformer/kubernetes/k8sutils_test.go +++ b/pkg/transformer/kubernetes/k8sutils_test.go @@ -661,7 +661,8 @@ func TestReadOnlyRootFS(t *testing.T) { func TestFormatEnvName(t *testing.T) { type args struct { - name string + name string + serviceName string } tests := []struct { name string @@ -694,12 +695,20 @@ func TestFormatEnvName(t *testing.T) { args: args{ name: "abcdefghijklnmopqrstuvxyzabcdefghijklmnopqrstuvwxyzabcdejghijkl$Hereisadditional", }, - want: "rstuvxyzabcdefghijklmnopqrstuvwxyzabcdejghijkl$Hereisadditional", + want: "abcdefghijklnmopqrstuvxyzabcdefghijklmnopqrstuvwxyzabcdejghijkl", + }, + { + name: "check that not begins with -", + args: args{ + name: "src/app/.env", + serviceName: "app", + }, + want: "app-env", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := FormatEnvName(tt.args.name); got != tt.want { + if got := FormatEnvName(tt.args.name, tt.args.serviceName); got != tt.want { t.Errorf("FormatEnvName() = %v, want %v", got, tt.want) } }) diff --git a/pkg/transformer/kubernetes/kubernetes.go b/pkg/transformer/kubernetes/kubernetes.go index f5b61971..a939536b 100644 --- a/pkg/transformer/kubernetes/kubernetes.go +++ b/pkg/transformer/kubernetes/kubernetes.go @@ -232,7 +232,7 @@ func (k *Kubernetes) InitConfigMapForEnv(name string, opt kobject.ConvertOptions // Remove root pathing // replace all other slashes / periods - envName := FormatEnvName(envFile) + envName := FormatEnvName(envFile, name) // In order to differentiate files, we append to the name and remove '.env' if applicable from the file name configMap := &api.ConfigMap{ @@ -1132,7 +1132,7 @@ func ConfigEnvs(service kobject.ServiceConfig, opt kobject.ConvertOptions) ([]ap if len(service.EnvFile) > 0 { // Load each env_file for _, file := range service.EnvFile { - envName := FormatEnvName(file) + envName := FormatEnvName(file, service.Name) // Load environment variables from file workDir, err := transformer.GetComposeFileDir(opt.InputFiles) From 8b9fcb382675712bc3da2e84a6d914c488894076 Mon Sep 17 00:00:00 2001 From: Martin Jirku Date: Sat, 27 Jan 2024 22:12:51 +0100 Subject: [PATCH 2/3] docs(1815): add trademarks link ref to linux foundation Signed-off-by: Martin Jirku --- docs/_includes/footer.html | 8 ++++++++ docs/assets/css/style.css | 11 ++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/_includes/footer.html b/docs/_includes/footer.html index 7c2eddfc..8989d780 100644 --- a/docs/_includes/footer.html +++ b/docs/_includes/footer.html @@ -7,6 +7,14 @@ Apache License 2.0 licensed project
© {{ site.year }} Kompose Authors -- All Rights Reserved +
+ Trademarks
diff --git a/docs/assets/css/style.css b/docs/assets/css/style.css index 1a76c3f7..ea74e5c7 100644 --- a/docs/assets/css/style.css +++ b/docs/assets/css/style.css @@ -3696,13 +3696,22 @@ font-family: "Open Sans"; .code-example { margin: 0; padding: 0; - margin-bottom 0px !important; + margin-bottom: 0px !important; background-color: transparent !important; } .copyright { color: #fff !important; font-size:13px; + padding-bottom: 12px; +} + +a.trademarks { + color: #fff !important; + font-weight:600; + display: inline-block; + text-decoration: underline; + padding: 0.8rem 0; } .highlight { From 4d4ff4e3948c5beddf278af0c249274b2aa8adbc Mon Sep 17 00:00:00 2001 From: Tomer Zait Date: Sun, 4 Feb 2024 12:07:05 +0200 Subject: [PATCH 3/3] fix client/convert (issue https://github.com/kubernetes/kompose/issues/1818) --- client/convert.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/convert.go b/client/convert.go index c56122b2..55d95d15 100644 --- a/client/convert.go +++ b/client/convert.go @@ -64,7 +64,7 @@ func (k *Kompose) setDefaultValues(options ConvertOptions) ConvertOptions { buildDefaultValue := "none" volumeTypeDefaultValue := "persistentVolumeClaim" withKomposeAnnotationsDefaultValue := true - kubernetesControllerDefaultValue := "deployment" + kubernetesControllerDefaultValue := "" kubernetesServiceGroupModeDefaultValue := "" if options.Replicas == nil { @@ -126,7 +126,7 @@ func (k *Kompose) validateOptions(options ConvertOptions) error { if kubernetesProvider, ok := options.Provider.(Kubernetes); ok { kubernetesController := kubernetesProvider.Controller - if *kubernetesController != string(DEPLOYMENT) && *kubernetesController != string(DAEMONSET) && *kubernetesController != string(REPLICATION_CONTROLLER) { + if *kubernetesController != "" && *kubernetesController != string(DEPLOYMENT) && *kubernetesController != string(DAEMONSET) && *kubernetesController != string(REPLICATION_CONTROLLER) { return fmt.Errorf( "unexpected Value for Kubernetes Controller field. Possible values are: %v, %v, and %v", string(DEPLOYMENT), string(DAEMONSET), string(REPLICATION_CONTROLLER), )