Skip to content

Commit

Permalink
Merge pull request spidernet-io#4245 from cyclinder/spidercontroller/…
Browse files Browse the repository at this point in the history
…pod_webhook_cert

Fix podwebhook cert don't update when spiderpool-controller restart
  • Loading branch information
weizhoublue authored Oct 31, 2024
2 parents 6586636 + cfda97b commit ea7f44d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions pkg/podmanager/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,18 @@ func AddPodMutatingWebhook(admissionClient admissionClientv1.Admissionregistrati
return fmt.Errorf("no any mutating webhook found in MutatingWebhookConfiguration %s", mutatingWebhookName)
}

var newWebhooks []admissionregistrationv1.MutatingWebhook
for _, wb := range mwc.Webhooks {
// if the webhook already exists, do nothing
if wb.Name == constant.PodMutatingWebhookName {
return nil
continue
}
newWebhooks = append(newWebhooks, wb)
}

podWebhook := InitPodMutatingWebhook(*mwc.Webhooks[0].DeepCopy(), webhookNamespaceInclude)
mwc.Webhooks = append(mwc.Webhooks, podWebhook)
newWebhooks = append(newWebhooks, podWebhook)
mwc.Webhooks = newWebhooks

_, updateErr := admissionClient.MutatingWebhookConfigurations().Update(context.TODO(), mwc, metav1.UpdateOptions{})
return updateErr
Expand Down
4 changes: 2 additions & 2 deletions pkg/podmanager/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ var _ = Describe("PodManager utils", Label("pod_manager_utils_test"), func() {
err = podmanager.AddPodMutatingWebhook(fakeClient.AdmissionregistrationV1(), webhookName, podWebhookNamespaceInclude)
Expect(err).NotTo(HaveOccurred())

// Verify the webhook was added
// // Verify the webhook was added
updatedConfig, err := fakeClient.AdmissionregistrationV1().MutatingWebhookConfigurations().Get(
context.TODO(), webhookName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
Expand All @@ -481,7 +481,7 @@ var _ = Describe("PodManager utils", Label("pod_manager_utils_test"), func() {
err = podmanager.AddPodMutatingWebhook(fakeClient.AdmissionregistrationV1(), webhookName, podWebhookNamespaceInclude)
Expect(err).NotTo(HaveOccurred())

// Verify no additional webhook was added
// // Verify no additional webhook was added
updatedConfig, err := fakeClient.AdmissionregistrationV1().MutatingWebhookConfigurations().Get(
context.TODO(), webhookName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
Expand Down
2 changes: 2 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ uninstall_spiderpool:
helm_upgrade_spiderpool:
@echo -e "\033[35m [helm upgrade spiderpool] \033[0m"
HELM_OPTION="";\
kubectl get mutatingwebhookconfigurations spiderpool-controller -o yaml --kubeconfig $(E2E_KUBECONFIG) ;\
HELM_OPTION+=" --set spiderpoolController.replicas=1 " ; \
if [ "$(INSTALL_OVERLAY_CNI)" == "true" ]; then \
HELM_OPTION+=" --set multus.multusCNI.defaultCniCRName= " ; \
Expand Down Expand Up @@ -464,6 +465,7 @@ helm_upgrade_spiderpool:
kubectl wait --for=condition=ready -l app.kubernetes.io/instance=spiderpool --timeout=300s pod -n $(RELEASE_NAMESPACE) --kubeconfig $(E2E_KUBECONFIG) || true; \
kubectl scale deploy -n $(RELEASE_NAMESPACE) -l app.kubernetes.io/component=spiderpool-controller --replicas=2 --kubeconfig $(E2E_KUBECONFIG); \
kubectl wait --for=condition=ready -l app.kubernetes.io/component=spiderpool-controller --timeout=300s pod -n $(RELEASE_NAMESPACE) --kubeconfig $(E2E_KUBECONFIG) || true; \
kubectl get mutatingwebhookconfigurations spiderpool-controller -o yaml --kubeconfig $(E2E_KUBECONFIG) ;\
helm --kubeconfig $(E2E_KUBECONFIG) list -A ; \

.PHONY: clean
Expand Down

0 comments on commit ea7f44d

Please sign in to comment.