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

add version labels to deployments managed by controllers #13176

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions pkg/controller/operator/common/util.go
Expand Up @@ -179,6 +179,28 @@ func VolumeRevisionLabelsModifierFactory(ctx context.Context, client ctrlruntime
}
}

// VersionLabelModifierFactory adds the version label for Deployments and their corresponding pods.
func VersionLabelModifierFactory(version string) reconciling.ObjectModifier {
return func(create reconciling.ObjectReconciler) reconciling.ObjectReconciler {
return func(existing ctrlruntimeclient.Object) (ctrlruntimeclient.Object, error) {
obj, err := create(existing)
if err != nil {
return obj, err
}

deployment, ok := obj.(*appsv1.Deployment)
if !ok {
return obj, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an error maybe. Silently not doing anything if someone used the modifier on something invalid could lead to sadness.

For other modifiers, like the volume revision thingy, I think we also support DaemonSets and StatefulSets -- if we decide to skip those here for now, it would be good if the code screamed at us if someone decided to use this in the future on a DS/STS.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is a really good point. Added an error

}

deployment.ObjectMeta.Labels[resources.VersionLabel] = version
deployment.Spec.Template.Labels[resources.VersionLabel] = version

return obj, nil
}
}
}

func createSecretData(s *corev1.Secret, data map[string]string) *corev1.Secret {
if s.Data == nil {
s.Data = make(map[string][]byte)
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/operator/master/reconciler.go
Expand Up @@ -342,6 +342,7 @@ func (r *Reconciler) reconcileDeployments(ctx context.Context, config *kubermati
modifiers := []reconciling.ObjectModifier{
common.OwnershipModifierFactory(config, r.scheme),
common.VolumeRevisionLabelsModifierFactory(ctx, r.Client),
common.VersionLabelModifierFactory(r.versions.Kubermatic),
}
// add the image pull secret wrapper only when an image pull secret is
// provided
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/operator/seed/reconciler.go
Expand Up @@ -569,6 +569,7 @@ func (r *Reconciler) reconcileDeployments(ctx context.Context, cfg *kubermaticv1
modifiers := []reconciling.ObjectModifier{
common.OwnershipModifierFactory(seed, r.scheme),
volumeLabelModifier,
common.VersionLabelModifierFactory(r.versions.Kubermatic),
}
// add the image pull secret wrapper only when an image pull secret is
// provided
Expand Down