Skip to content

Commit

Permalink
Do not keep orphaned replicaset fro function managed deployments (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwiatekus authored Mar 14, 2024
1 parent 60b1a49 commit 8476bf3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
)

func TestFunctionReconciler_equalDeployments(t *testing.T) {

ten := int32(10)
zero := int32(0)
type args struct {
existing appsv1.Deployment
expected appsv1.Deployment
Expand Down Expand Up @@ -454,6 +457,22 @@ func TestFunctionReconciler_equalDeployments(t *testing.T) {
},
want: false,
},
{
name: "different revision history limit",
args: args{
existing: appsv1.Deployment{
Spec: appsv1.DeploymentSpec{
RevisionHistoryLimit: &ten,
},
},
expected: appsv1.Deployment{
Spec: appsv1.DeploymentSpec{
RevisionHistoryLimit: &zero,
},
},
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -1021,9 +1040,11 @@ func TestFunctionReconciler_isDeploymentReady(t *testing.T) {
}

func fixDeploymentWithReplicas(replicas int32) appsv1.Deployment {
zero := int32(0)
return appsv1.Deployment{
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
RevisionHistoryLimit: &zero,
Replicas: &replicas,
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{{}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,14 +518,16 @@ func (s *systemState) buildDeployment(cfg buildDeploymentArgs, resourceConfig Re
}
enrichPodSpecWithSecurityContext(&templateSpec, functionUser, functionUserGroup)

zero := int32(0)
return appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
GenerateName: fmt.Sprintf("%s-", s.instance.GetName()),
Namespace: s.instance.GetNamespace(),
Labels: s.functionLabels(),
},
Spec: appsv1.DeploymentSpec{
Replicas: s.getReplicas(DefaultDeploymentReplicas),
RevisionHistoryLimit: &zero,
Replicas: s.getReplicas(DefaultDeploymentReplicas),
Selector: &metav1.LabelSelector{
MatchLabels: s.deploymentSelectorLabels(), // this has to match spec.template.objectmeta.Labels
// and also it has to be immutable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func equalDeployments(existing appsv1.Deployment, expected appsv1.Deployment) bo

result = result && mapsEqual(existing.Spec.Template.GetAnnotations(), expected.Spec.Template.GetAnnotations())
result = result && equalSecretMounts(existing.Spec.Template.Spec, expected.Spec.Template.Spec)
result = result && equalInt32Pointer(existing.Spec.RevisionHistoryLimit, expected.Spec.RevisionHistoryLimit)
return result
}

Expand Down

0 comments on commit 8476bf3

Please sign in to comment.