Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply label prefix rules for cm and secrets #743

Merged
merged 1 commit into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pkg/canary/config_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (ct *ConfigTracker) HasConfigChanged(cd *flaggerv1.Canary) (bool, error) {

// CreatePrimaryConfigs syncs the primary Kubernetes ConfigMaps and Secretes
// with those found in the target deployment
func (ct *ConfigTracker) CreatePrimaryConfigs(cd *flaggerv1.Canary, refs map[string]ConfigRef) error {
func (ct *ConfigTracker) CreatePrimaryConfigs(cd *flaggerv1.Canary, refs map[string]ConfigRef, includeLabelPrefix []string) error {
for _, ref := range refs {
switch ref.Type {
case ConfigRefMap:
Expand All @@ -272,11 +272,12 @@ func (ct *ConfigTracker) CreatePrimaryConfigs(cd *flaggerv1.Canary, refs map[str
return fmt.Errorf("configmap %s.%s get query failed : %w", ref.Name, cd.Name, err)
}
primaryName := fmt.Sprintf("%s-primary", config.GetName())
labels := includeLabelsByPrefix(config.Labels, includeLabelPrefix)
primaryConfigMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: primaryName,
Namespace: cd.Namespace,
Labels: config.Labels,
Labels: labels,
OwnerReferences: []metav1.OwnerReference{
*metav1.NewControllerRef(cd, schema.GroupVersionKind{
Group: flaggerv1.SchemeGroupVersion.Group,
Expand Down Expand Up @@ -309,11 +310,12 @@ func (ct *ConfigTracker) CreatePrimaryConfigs(cd *flaggerv1.Canary, refs map[str
return fmt.Errorf("secret %s.%s get query failed : %w", ref.Name, cd.Name, err)
}
primaryName := fmt.Sprintf("%s-primary", secret.GetName())
labels := includeLabelsByPrefix(secret.Labels, includeLabelPrefix)
primarySecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: primaryName,
Namespace: cd.Namespace,
Labels: secret.Labels,
Labels: labels,
OwnerReferences: []metav1.OwnerReference{
*metav1.NewControllerRef(cd, schema.GroupVersionKind{
Group: flaggerv1.SchemeGroupVersion.Group,
Expand Down
4 changes: 2 additions & 2 deletions pkg/canary/daemonset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (c *DaemonSetController) Promote(cd *flaggerv1.Canary) error {
if err != nil {
return fmt.Errorf("GetTargetConfigs failed: %w", err)
}
if err := c.configTracker.CreatePrimaryConfigs(cd, configRefs); err != nil {
if err := c.configTracker.CreatePrimaryConfigs(cd, configRefs, c.includeLabelPrefix); err != nil {
return fmt.Errorf("CreatePrimaryConfigs failed: %w", err)
}

Expand Down Expand Up @@ -232,7 +232,7 @@ func (c *DaemonSetController) createPrimaryDaemonSet(cd *flaggerv1.Canary, inclu
if err != nil {
return fmt.Errorf("GetTargetConfigs failed: %w", err)
}
if err := c.configTracker.CreatePrimaryConfigs(cd, configRefs); err != nil {
if err := c.configTracker.CreatePrimaryConfigs(cd, configRefs, c.includeLabelPrefix); err != nil {
return fmt.Errorf("CreatePrimaryConfigs failed: %w", err)
}
annotations, err := makeAnnotations(canaryDae.Spec.Template.Annotations)
Expand Down
4 changes: 2 additions & 2 deletions pkg/canary/deployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (c *DeploymentController) Promote(cd *flaggerv1.Canary) error {
if err != nil {
return fmt.Errorf("GetTargetConfigs failed: %w", err)
}
if err := c.configTracker.CreatePrimaryConfigs(cd, configRefs); err != nil {
if err := c.configTracker.CreatePrimaryConfigs(cd, configRefs, c.includeLabelPrefix); err != nil {
return fmt.Errorf("CreatePrimaryConfigs failed: %w", err)
}

Expand Down Expand Up @@ -228,7 +228,7 @@ func (c *DeploymentController) createPrimaryDeployment(cd *flaggerv1.Canary, inc
if err != nil {
return fmt.Errorf("GetTargetConfigs failed: %w", err)
}
if err := c.configTracker.CreatePrimaryConfigs(cd, configRefs); err != nil {
if err := c.configTracker.CreatePrimaryConfigs(cd, configRefs, c.includeLabelPrefix); err != nil {
return fmt.Errorf("CreatePrimaryConfigs failed: %w", err)
}
annotations, err := makeAnnotations(canaryDep.Spec.Template.Annotations)
Expand Down
2 changes: 1 addition & 1 deletion pkg/canary/nop_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (nt *NopTracker) HasConfigChanged(*flaggerv1.Canary) (bool, error) {
return false, nil
}

func (nt *NopTracker) CreatePrimaryConfigs(*flaggerv1.Canary, map[string]ConfigRef) error {
func (nt *NopTracker) CreatePrimaryConfigs(*flaggerv1.Canary, map[string]ConfigRef, []string) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/canary/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ type Tracker interface {
GetTargetConfigs(cd *flaggerv1.Canary) (map[string]ConfigRef, error)
GetConfigRefs(cd *flaggerv1.Canary) (*map[string]string, error)
HasConfigChanged(cd *flaggerv1.Canary) (bool, error)
CreatePrimaryConfigs(cd *flaggerv1.Canary, refs map[string]ConfigRef) error
CreatePrimaryConfigs(cd *flaggerv1.Canary, refs map[string]ConfigRef, includeLabelPrefix []string) error
ApplyPrimaryConfigs(spec corev1.PodSpec, refs map[string]ConfigRef) corev1.PodSpec
}