Merge branch 'kubernetes:main' into fix-issue-1778

This commit is contained in:
Jose Luis 2024-02-07 18:35:28 +01:00 committed by GitHub
commit 182e0ce294
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 52 additions and 13 deletions

View File

@ -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),
)

View File

@ -7,6 +7,14 @@
Apache License 2.0 licensed project
<br>
© {{ site.year }} Kompose Authors -- All Rights Reserved
<br />
<a
class="trademarks"
href="https://www.linuxfoundation.org/legal/trademark-usage"
target="_blank"
ref="noopener"
>Trademarks</a
>
</span>
</div>
<div class="container">

View File

@ -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 {

View File

@ -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

View File

@ -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)
}
})

View File

@ -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{
@ -1133,7 +1133,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)