Skip to content

Commit

Permalink
Fix problem where healthz/readyz would not wait for webhook server to…
Browse files Browse the repository at this point in the history
… start (#303)
  • Loading branch information
orishoshan authored Dec 4, 2023
1 parent 2fc662c commit 1b5f45d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,21 +258,28 @@ func (s *ExternalNetworkPolicyReconcilerTestSuite) TestNetworkPolicyCreateForLoa
assert.NotNil(intentsDeleted.DeletionTimestamp)
})

res, err = s.NetworkPolicyReconciler.Reconcile(context.Background(), ctrl.Request{
NamespacedName: types.NamespacedName{
Namespace: s.TestNamespace,
Name: intents.Name,
},
})
s.Require().NoError(err)
s.Require().Empty(res)

s.WaitUntilCondition(func(assert *assert.Assertions) {
res, err = s.NetworkPolicyReconciler.Reconcile(context.Background(), ctrl.Request{
NamespacedName: types.NamespacedName{
Namespace: s.TestNamespace,
Name: intents.Name,
},
})
s.Require().NoError(err)
s.Require().Empty(res)
err = s.Mgr.GetClient().Get(context.Background(), types.NamespacedName{Namespace: s.TestNamespace, Name: intentNetworkPolicyName}, &v1.NetworkPolicy{})
assert.True(errors.IsNotFound(err))
})

s.WaitUntilCondition(func(assert *assert.Assertions) {
res, err = s.NetworkPolicyReconciler.Reconcile(context.Background(), ctrl.Request{
NamespacedName: types.NamespacedName{
Namespace: s.TestNamespace,
Name: intents.Name,
},
})
s.Require().NoError(err)
s.Require().Empty(res)
err = s.Mgr.GetClient().Get(context.Background(), types.NamespacedName{Namespace: s.TestNamespace, Name: externalNetworkPolicyName}, &v1.NetworkPolicy{})
assert.True(errors.IsNotFound(err))
})
Expand Down
9 changes: 4 additions & 5 deletions src/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,12 @@ import (
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"

otterizev1alpha3 "github.com/otterize/intents-operator/src/operator/api/v1alpha3"
istiosecurityscheme "istio.io/client-go/pkg/apis/security/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"

otterizev1alpha3 "github.com/otterize/intents-operator/src/operator/api/v1alpha3"
//+kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -412,11 +410,12 @@ func main() {
if err != nil {
logrus.WithError(err).Panic()
}

//+kubebuilder:scaffold:builder
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
if err := mgr.AddHealthzCheck("healthz", mgr.GetWebhookServer().StartedChecker()); err != nil {
logrus.WithError(err).Fatal("unable to set up health check")
}
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
if err := mgr.AddReadyzCheck("readyz", mgr.GetWebhookServer().StartedChecker()); err != nil {
logrus.WithError(err).Fatal("unable to set up ready check")
}

Expand Down

0 comments on commit 1b5f45d

Please sign in to comment.