Skip to content

Commit

Permalink
fix: do not check if affinity is empty.
Browse files Browse the repository at this point in the history
The policy server reconciler check if the policy server spec has a non
empty affinity. If that's the case, it set the affinity in the policy
server deployment. This allow users to set the affinity manually in the
deployment. This should not be allowed. The policy server CRDS should be
the interface to configure the affinity. Therefore, that check is
removed and the affinity from the policy server spec is always set in
the deployment.

Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
  • Loading branch information
jvanz committed Jul 4, 2024
1 parent 8b4790e commit 6e105ed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 1 addition & 4 deletions internal/controller/policyserver_controller_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func (r *PolicyServerReconciler) updatePolicyServerDeployment(policyServer *poli
Containers: []corev1.Container{admissionContainer},
ServiceAccountName: policyServer.Spec.ServiceAccountName,
Tolerations: policyServer.Spec.Tolerations,
Affinity: &policyServer.Spec.Affinity,
Volumes: []corev1.Volume{
{
Name: policyStoreVolume,
Expand Down Expand Up @@ -296,10 +297,6 @@ func (r *PolicyServerReconciler) adaptDeploymentSettingsForPolicyServer(policySe
},
)
}

if emptyAffinity := (corev1.Affinity{}); policyServer.Spec.Affinity != emptyAffinity {
policyServerDeployment.Spec.Template.Spec.Affinity = &policyServer.Spec.Affinity
}
}

func envVarsContainVariable(envVars []corev1.EnvVar, envVarName string) int {
Expand Down
6 changes: 5 additions & 1 deletion internal/controller/policyserver_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,11 @@ var _ = Describe("PolicyServer controller", func() {
"FSGroupChangePolicy": BeNil(),
"SeccompProfile": BeNil(),
})),
"Affinity": BeNil(),
"Affinity": PointTo(MatchAllFields(Fields{
"NodeAffinity": BeNil(),
"PodAffinity": BeNil(),
"PodAntiAffinity": BeNil(),
})),
}))
})

Expand Down

0 comments on commit 6e105ed

Please sign in to comment.