Skip to content

Commit

Permalink
MULTIARCH-4304: Remove logic and test checking for correct podplaceme…
Browse files Browse the repository at this point in the history
…ntconfig name
  • Loading branch information
AnnaZivkovic committed May 8, 2024
1 parent 6f3bb25 commit e7a42e9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 33 deletions.
23 changes: 4 additions & 19 deletions controllers/operator/podplacementconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,11 @@ func (r *PodPlacementConfigReconciler) Reconcile(ctx context.Context, req ctrl.R
}

log.V(3).Info("PodPlacementConfig fetched...", "name", podPlacementConfig.Name)
if req.NamespacedName.Name == multiarchv1alpha1.SingletonResourceObjectName {
if apierrors.IsNotFound(err) || !podPlacementConfig.DeletionTimestamp.IsZero() {
// Only execute deletion iff the name of the object is 'cluster' and the object is being deleted or not found
return ctrl.Result{}, r.handleDelete(ctx)
}
return ctrl.Result{}, r.reconcile(ctx, podPlacementConfig)
}

// If we hit here, the PodPlacementConfig has an invalid name.
log.V(3).Info("PodPlacementConfig name is not cluster", "name", podPlacementConfig.Name)
if podPlacementConfig.DeletionTimestamp.IsZero() {
// Only execute deletion iff the name of the object is different from 'cluster' and the object is not yet deleted.
log.V(3).Info("Deleting PodPlacementConfig", "name", podPlacementConfig.Name)
err := r.Delete(ctx, podPlacementConfig)
if err != nil {
return ctrl.Result{}, err
}
if apierrors.IsNotFound(err) || !podPlacementConfig.DeletionTimestamp.IsZero() {
// Only execute deletion iff the name of the object is 'cluster' and the object is being deleted or not found
return ctrl.Result{}, r.handleDelete(ctx)
}
log.Info("The PodPlacementConfig is already pending deletion, nothing to do.", "name", podPlacementConfig.Name)
return ctrl.Result{}, nil
return ctrl.Result{}, r.reconcile(ctx, podPlacementConfig)
}

// handleDelete handles the deletion of the PodPlacement operand's resources.
Expand Down
14 changes: 1 addition & 13 deletions controllers/operator/podplacementconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,7 @@ var _ = Describe("Controllers/PodPlacementConfig/PodPlacementConfigReconciler",
It("should refuse to create a PodPlacementConfig with an invalid name", func() {
ppc := newPodPlacementConfig().WithName("invalid-name").Build()
err := k8sClient.Create(ctx, ppc)
Expect(err).NotTo(HaveOccurred(), "failed to create PodPlacementConfig", err)
Eventually(func(g Gomega) {
ppc := &v1alpha1.PodPlacementConfig{}
err := k8sClient.Get(ctx, crclient.ObjectKeyFromObject(&v1alpha1.PodPlacementConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "invalid-name",
Namespace: utils.Namespace(),
},
}), ppc)
g.Expect(err).To(HaveOccurred(), "An error should have been detected")
g.Expect(crclient.IgnoreNotFound(err)).NotTo(HaveOccurred(),
"The error should not be different than a NotFound error")
}).Should(Succeed())
Expect(err).To(HaveOccurred(), "failed to create PodPlacementConfig", err)
})
It("should reconcile the deployment pod-placement-controller", func() {
// get the deployment
Expand Down
5 changes: 4 additions & 1 deletion controllers/podplacement/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ var _ = AfterSuite(func() {
func startTestEnv() {
By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
CRDDirectoryPaths: []string{
filepath.Join("..", "..", "config", "crd", "bases"),
filepath.Join("..", "..", "config", "crd", "patches"),
},
ErrorIfCRDPathMissing: true,
WebhookInstallOptions: envtest.WebhookInstallOptions{
MutatingWebhooks: []*v1.MutatingWebhookConfiguration{getMutatingWebHook()},
Expand Down

0 comments on commit e7a42e9

Please sign in to comment.