mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-29 21:31:02 +00:00
kubernetes ignore labels and annotations if not set (#1528)
close #1527 regression of #1510
This commit is contained in:
parent
f1e9c8416d
commit
5c617accd8
1 changed files with 17 additions and 13 deletions
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue