forked from LaconicNetwork/kompose
in case /run/secrets/MARIADB_PASSWORD and secrets: MARIADB_PASSWORD are in uppercase, reformat the value of MARIADB_PASSWORD to mariadb-password. Also, reformat the secretconfig of the secrets. getSecretPathsLegacy returns secretSubPath. (#1826)
Signed-off-by: jose luis <2064537+sosan@users.noreply.github.com>
This commit is contained in:
parent
d872afb377
commit
c0f7e910c8
@ -31,6 +31,7 @@ import (
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/kubernetes/kompose/pkg/kobject"
|
||||
"github.com/kubernetes/kompose/pkg/loader/compose"
|
||||
@ -971,3 +972,20 @@ func GetFileName(fileName string) string {
|
||||
// Not format filename because can begin with .fileName
|
||||
return fileName
|
||||
}
|
||||
|
||||
// reformatSecretConfigUnderscoreWithDash takes a ServiceSecretConfig object as input and returns a new instance of ServiceSecretConfig
|
||||
// where the values of Source and Target are formatted using the FormatResourceName function to replace underscores with dashes and lowercase,
|
||||
// while the other fields remain unchanged. This is done to ensure consistency in the format of container names within the service's secret configuration.
|
||||
// this function ensures that source, target names are in an acceptable format for Kubernetes and other systems that may require a specific naming format.
|
||||
func reformatSecretConfigUnderscoreWithDash(secretConfig types.ServiceSecretConfig) types.ServiceSecretConfig {
|
||||
newSecretConfig := types.ServiceSecretConfig{
|
||||
Source: FormatResourceName(secretConfig.Source),
|
||||
Target: FormatResourceName(secretConfig.Target),
|
||||
UID: secretConfig.UID,
|
||||
GID: secretConfig.GID,
|
||||
Mode: secretConfig.Mode,
|
||||
Extensions: secretConfig.Extensions,
|
||||
}
|
||||
|
||||
return newSecretConfig
|
||||
}
|
||||
|
||||
@ -582,18 +582,18 @@ func (k *Kubernetes) CreateSecrets(komposeObject kobject.KomposeObject) ([]*api.
|
||||
return nil, err
|
||||
}
|
||||
data := []byte(dataString)
|
||||
fileName := GetFileName(config.File)
|
||||
resourceName := FormatResourceName(name)
|
||||
secret := &api.Secret{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Secret",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: FormatResourceName(name),
|
||||
Labels: transformer.ConfigLabels(name),
|
||||
Name: resourceName,
|
||||
Labels: transformer.ConfigLabels(resourceName),
|
||||
},
|
||||
Type: api.SecretTypeOpaque,
|
||||
Data: map[string][]byte{fileName: data},
|
||||
Data: map[string][]byte{resourceName: data},
|
||||
}
|
||||
objects = append(objects, secret)
|
||||
} else {
|
||||
@ -800,6 +800,7 @@ func (k *Kubernetes) ConfigSecretVolumes(name string, service kobject.ServiceCon
|
||||
var volumes []api.Volume
|
||||
if len(service.Secrets) > 0 {
|
||||
for _, secretConfig := range service.Secrets {
|
||||
secretConfig := reformatSecretConfigUnderscoreWithDash(secretConfig)
|
||||
if secretConfig.UID != "" {
|
||||
log.Warnf("Ignore pid in secrets for service: %s", name)
|
||||
}
|
||||
@ -911,8 +912,8 @@ func (k *Kubernetes) getSecretPathsLegacy(secretConfig types.ServiceSecretConfig
|
||||
itemPath = lastPart
|
||||
}
|
||||
|
||||
secretSubPath = "" // We didn't set a SubPath in legacy behavior
|
||||
return itemPath, mountPath, ""
|
||||
secretSubPath = itemPath //"" // We didn't set a SubPath in legacy behavior
|
||||
return itemPath, mountPath, secretSubPath
|
||||
}
|
||||
|
||||
// ConfigVolumes configure the container volumes.
|
||||
@ -1165,6 +1166,9 @@ func ConfigEnvs(service kobject.ServiceConfig, opt kobject.ConvertOptions) ([]ap
|
||||
// Load up the environment variables
|
||||
for _, v := range service.Environment {
|
||||
if !keysFromEnvFile[v.Name] {
|
||||
if strings.Contains(v.Value, "run/secrets") {
|
||||
v.Value = FormatResourceName(v.Value)
|
||||
}
|
||||
envs = append(envs, api.EnvVar{
|
||||
Name: v.Name,
|
||||
Value: v.Value,
|
||||
|
||||
@ -1196,7 +1196,7 @@ func TestKubernetes_CreateSecrets(t *testing.T) {
|
||||
Labels: transformer.ConfigLabels(dataSecrets[0].nameSecretConfig),
|
||||
},
|
||||
Type: api.SecretTypeOpaque,
|
||||
Data: map[string][]byte{"CNAME": []byte("kompose.io")},
|
||||
Data: map[string][]byte{dataSecrets[0].nameSecretConfig: []byte("kompose.io")},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -1216,7 +1216,7 @@ func TestKubernetes_CreateSecrets(t *testing.T) {
|
||||
Labels: transformer.ConfigLabels(dataSecrets[1].nameSecretConfig),
|
||||
},
|
||||
Type: api.SecretTypeOpaque,
|
||||
Data: map[string][]byte{"CNAME": []byte("kompose.io")},
|
||||
Data: map[string][]byte{dataSecrets[1].nameSecretConfig: []byte("kompose.io")},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user