Skip to content

Commit 5f73549

Browse files
Merge pull request #224 from slintes/mhc_support
MHC support
2 parents 98560cc + ce949ea commit 5f73549

File tree

1,925 files changed

+272876
-27068
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,925 files changed

+272876
-27068
lines changed

.github/workflows/pre-submit.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ jobs:
141141
- name: Run NHC e2e
142142
run: |
143143
echo "running e2e test"
144-
OPERATOR_NS=${DEPLOY_NAMESPACE} TEST_OPTS='-ginkgo.label-filter="!OCP-ONLY"' make test-e2e
144+
OPERATOR_NS=${DEPLOY_NAMESPACE} LABEL_FILTER="!OCP-ONLY" make test-e2e
145145
echo "finished e2e test"
146146
147147
- name: Debug

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ bundle-run: operator-sdk ## Run bundle image
364364

365365
.PHONY: bundle-cleanup
366366
bundle-cleanup: operator-sdk ## Remove bundle installed via bundle-run
367-
$(OPERATOR_SDK) -n openshift-operators cleanup node-healthcheck-operator
367+
$(OPERATOR_SDK) -n openshift-operators cleanup node-healthcheck-operator --delete-all
368368

369369
# Build a index image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
370370
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
@@ -379,11 +379,8 @@ index-push: ## Push a catalog image.
379379
podman push $(INDEX_IMG)
380380

381381
.PHONY: test-e2e
382-
export OPERATOR_NS ?= openshift-operators
383382
test-e2e: ## Run end to end tests
384-
@test -n "${KUBECONFIG}" -o -r ${HOME}/.kube/config || (echo "Failed to find kubeconfig in ~/.kube/config or no KUBECONFIG set"; exit 1)
385-
echo "Running e2e tests"
386-
go test ./e2e -coverprofile cover.out -timeout 60m -test.v -ginkgo.vv $(TEST_OPTS)
383+
./hack/test-e2e.sh
387384

388385

389386
.PHONY: deploy-snr ## Deploy self node remediation to a running cluster
@@ -411,4 +408,7 @@ container-build-metrics: ## Build containers
411408

412409
.PHONY: container-push
413410
container-push: ## Push containers (NOTE: catalog can't be build before bundle was pushed)
414-
make docker-push bundle-push index-build index-push
411+
make docker-push bundle-push #index-build index-push
412+
413+
.PHONY: build-and-run
414+
build-and-run: container-build container-push bundle-run

api/v1alpha1/nodehealthcheck_webhook.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
ctrl "sigs.k8s.io/controller-runtime"
2929
logf "sigs.k8s.io/controller-runtime/pkg/log"
3030
"sigs.k8s.io/controller-runtime/pkg/webhook"
31+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
3132
)
3233

3334
const (
@@ -56,36 +57,36 @@ func (nhc *NodeHealthCheck) SetupWebhookWithManager(mgr ctrl.Manager) error {
5657
var _ webhook.Validator = &NodeHealthCheck{}
5758

5859
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
59-
func (nhc *NodeHealthCheck) ValidateCreate() error {
60+
func (nhc *NodeHealthCheck) ValidateCreate() (warnings admission.Warnings, err error) {
6061
nodehealthchecklog.Info("validate create", "name", nhc.Name)
61-
return nhc.validate()
62+
return admission.Warnings{}, nhc.validate()
6263
}
6364

6465
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
65-
func (nhc *NodeHealthCheck) ValidateUpdate(old runtime.Object) error {
66+
func (nhc *NodeHealthCheck) ValidateUpdate(old runtime.Object) (warnings admission.Warnings, err error) {
6667
nodehealthchecklog.Info("validate update", "name", nhc.Name)
6768

6869
// do the normal validation
6970
if err := nhc.validate(); err != nil {
70-
return err
71+
return admission.Warnings{}, err
7172
}
7273

7374
// during ongoing remediations, some updates are forbidden
7475
if nhc.isRemediating() {
7576
if updated, field := nhc.isRestrictedFieldUpdated(old.(*NodeHealthCheck)); updated {
76-
return fmt.Errorf("%s update %s", field, OngoingRemediationError)
77+
return admission.Warnings{}, fmt.Errorf("%s update %s", field, OngoingRemediationError)
7778
}
7879
}
79-
return nil
80+
return admission.Warnings{}, nil
8081
}
8182

8283
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
83-
func (nhc *NodeHealthCheck) ValidateDelete() error {
84+
func (nhc *NodeHealthCheck) ValidateDelete() (warnings admission.Warnings, err error) {
8485
nodehealthchecklog.Info("validate delete", "name", nhc.Name)
8586
if nhc.isRemediating() {
86-
return fmt.Errorf("deletion %s", OngoingRemediationError)
87+
return admission.Warnings{}, fmt.Errorf("deletion %s", OngoingRemediationError)
8788
}
88-
return nil
89+
return admission.Warnings{}, nil
8990
}
9091

9192
func (nhc *NodeHealthCheck) validate() error {

api/v1alpha1/nodehealthcheck_webhook_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import (
55

66
. "github.com/onsi/ginkgo/v2"
77
. "github.com/onsi/gomega"
8+
"github.com/onsi/gomega/types"
89

910
v1 "k8s.io/api/core/v1"
1011
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12+
"k8s.io/apimachinery/pkg/runtime"
1113
"k8s.io/apimachinery/pkg/util/intstr"
14+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
1215
)
1316

1417
var _ = Describe("NodeHealthCheck Validation", func() {
@@ -192,18 +195,25 @@ var _ = Describe("NodeHealthCheck Validation", func() {
192195
}
193196
})
194197

198+
validateError := func(validate func(obj runtime.Object) (admission.Warnings, error), nhc *NodeHealthCheck, substrings ...string) {
199+
warnings, err := validate(nhc)
200+
ExpectWithOffset(1, warnings).To(BeEmpty())
201+
matchers := make([]types.GomegaMatcher, 0)
202+
for _, substring := range substrings {
203+
matchers = append(matchers, ContainSubstring(substring))
204+
}
205+
ExpectWithOffset(1, err).To(MatchError(
206+
And(matchers...),
207+
))
208+
}
209+
195210
Context("updating selector", func() {
196211
BeforeEach(func() {
197212
nhcNew = nhcOld.DeepCopy()
198213
nhcNew.Spec.Selector.MatchExpressions[0].Key = "node-role.kubernetes.io/infra"
199214
})
200215
It("should be denied", func() {
201-
Expect(nhcNew.ValidateUpdate(nhcOld)).To(MatchError(
202-
And(
203-
ContainSubstring(OngoingRemediationError),
204-
ContainSubstring("selector"),
205-
),
206-
))
216+
validateError(nhcNew.ValidateUpdate, nhcOld, OngoingRemediationError, "selector")
207217
})
208218
})
209219

@@ -213,12 +223,7 @@ var _ = Describe("NodeHealthCheck Validation", func() {
213223
nhcNew.Spec.RemediationTemplate.Name = "newName"
214224
})
215225
It("should be denied", func() {
216-
Expect(nhcNew.ValidateUpdate(nhcOld)).To(MatchError(
217-
And(
218-
ContainSubstring(OngoingRemediationError),
219-
ContainSubstring("remediation template"),
220-
),
221-
))
226+
validateError(nhcNew.ValidateUpdate, nhcOld, OngoingRemediationError, "remediation template")
222227
})
223228
})
224229

@@ -229,12 +234,7 @@ var _ = Describe("NodeHealthCheck Validation", func() {
229234
nhcNew.Spec.EscalatingRemediations[0].Order = 42
230235
})
231236
It("should be denied", func() {
232-
Expect(nhcNew.ValidateUpdate(nhcOld)).To(MatchError(
233-
And(
234-
ContainSubstring(OngoingRemediationError),
235-
ContainSubstring("escalating remediations"),
236-
),
237-
))
237+
validateError(nhcNew.ValidateUpdate, nhcOld, OngoingRemediationError, "escalating remediations")
238238
})
239239
})
240240
})

bundle/manifests/node-healthcheck-operator.clusterserviceversion.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,14 @@ spec:
254254
- get
255255
- list
256256
- watch
257+
- apiGroups:
258+
- config.openshift.io
259+
resources:
260+
- featuregates
261+
verbs:
262+
- get
263+
- list
264+
- watch
257265
- apiGroups:
258266
- console.openshift.io
259267
resources:
@@ -300,7 +308,17 @@ spec:
300308
verbs:
301309
- get
302310
- list
311+
- patch
312+
- update
303313
- watch
314+
- apiGroups:
315+
- machine.openshift.io
316+
resources:
317+
- machinehealthchecks/status
318+
verbs:
319+
- get
320+
- patch
321+
- update
304322
- apiGroups:
305323
- machine.openshift.io
306324
resources:

config/rbac/role.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ rules:
2020
- get
2121
- list
2222
- watch
23+
- apiGroups:
24+
- config.openshift.io
25+
resources:
26+
- featuregates
27+
verbs:
28+
- get
29+
- list
30+
- watch
2331
- apiGroups:
2432
- console.openshift.io
2533
resources:
@@ -66,7 +74,17 @@ rules:
6674
verbs:
6775
- get
6876
- list
77+
- patch
78+
- update
6979
- watch
80+
- apiGroups:
81+
- machine.openshift.io
82+
resources:
83+
- machinehealthchecks/status
84+
verbs:
85+
- get
86+
- patch
87+
- update
7088
- apiGroups:
7189
- machine.openshift.io
7290
resources:

0 commit comments

Comments
 (0)