kubernetes ignore labels and annotations if not set (#1528)

close #1527
regression of #1510
This commit is contained in:
6543 2023-01-04 18:51:21 +01:00 committed by GitHub
parent f1e9c8416d
commit 5c617accd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -43,30 +43,34 @@ type Config struct {
Namespace string Namespace string
StorageClass string StorageClass string
VolumeSize string VolumeSize string
StorageRwx bool
PodLabels map[string]string PodLabels map[string]string
PodAnnotations map[string]string PodAnnotations map[string]string
StorageRwx bool
} }
func configFromCliContext(ctx context.Context) (*Config, error) { func configFromCliContext(ctx context.Context) (*Config, error) {
if ctx != nil { if ctx != nil {
if c, ok := ctx.Value(types.CliContext).(*cli.Context); ok { if c, ok := ctx.Value(types.CliContext).(*cli.Context); ok {
config := Config{ config := Config{
Namespace: c.String("backend-k8s-namespace"), Namespace: c.String("backend-k8s-namespace"),
StorageClass: c.String("backend-k8s-storage-class"), StorageClass: c.String("backend-k8s-storage-class"),
VolumeSize: c.String("backend-k8s-volume-size"), VolumeSize: c.String("backend-k8s-volume-size"),
StorageRwx: c.Bool("backend-k8s-storage-rwx"), StorageRwx: c.Bool("backend-k8s-storage-rwx"),
PodLabels: make(map[string]string), // just init empty map to prevent nil panic
PodAnnotations: make(map[string]string), // just init empty map to prevent nil panic
} }
// Unmarshal label and annotation settings here to ensure they're valid on startup // Unmarshal label and annotation settings here to ensure they're valid on startup
err := yaml.Unmarshal([]byte(c.String("backend-k8s-pod-labels")), &config.PodLabels) if labels := c.String("backend-k8s-pod-labels"); labels != "" {
if err != nil { if err := yaml.Unmarshal([]byte(labels), &config.PodLabels); err != nil {
log.Error().Msgf("could not unmarshal pod labels '%s': %s", c.String("backend-k8s-pod-labels"), err) log.Error().Msgf("could not unmarshal pod labels '%s': %s", c.String("backend-k8s-pod-labels"), err)
return nil, err return nil, err
}
} }
err = yaml.Unmarshal([]byte(c.String("backend-k8s-pod-annotations")), &config.PodAnnotations) if annotations := c.String("backend-k8s-pod-annotations"); annotations != "" {
if err != nil { if err := yaml.Unmarshal([]byte(c.String("backend-k8s-pod-annotations")), &config.PodAnnotations); err != nil {
log.Error().Msgf("could not unmarshal pod annotations '%s': %s", c.String("backend-k8s-pod-annotations"), err) log.Error().Msgf("could not unmarshal pod annotations '%s': %s", c.String("backend-k8s-pod-annotations"), err)
return nil, err return nil, err
}
} }
return &config, nil return &config, nil
} }