Skip to content

Commit 0b557d9

Browse files
authored
Merge pull request #461 from andreaskaris/reconcile
bpfman-operator: Add Config resource and update reconciler and tests
2 parents ace851d + f00edc4 commit 0b557d9

Some content is hidden

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

41 files changed

+3235
-904
lines changed

.github/workflows/integration_test.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@ on:
99

1010
jobs:
1111
kubernetes-integration-tests:
12-
name: Kubernetes Integration Tests (Go ${{ matrix.go }} - amd64 - ${{ matrix.oci_bin }})
12+
name: Kubernetes Integration Tests (Go ${{ matrix.go }} - amd64 - ${{ matrix.oci_bin }} - ${{ matrix.command }})
1313
runs-on: ubuntu-24.04
1414
strategy:
1515
matrix:
1616
go: ["1.24"]
1717
oci_bin: ["docker", "podman"]
18+
command: [
19+
"integration",
20+
"lifecycle"
21+
]
22+
exclude:
23+
- oci_bin: podman
24+
command: "lifecycle"
1825
env:
1926
BPFMAN_AGENT_IMG: quay.io/bpfman/bpfman-agent:int-test
2027
BPFMAN_OPERATOR_IMG: quay.io/bpfman/bpfman-operator:int-test
@@ -64,10 +71,16 @@ jobs:
6471
6572
# Run integration tests only if OCI_BIN is Docker.
6673
- name: Run integration tests
67-
if: ${{ matrix.oci_bin == 'docker' }}
74+
if: ${{ (matrix.oci_bin == 'docker') && (matrix.command == 'integration') }}
6875
run: |
6976
make test-integration
7077
78+
# Run lifecycle tests only if OCI_BIN is Docker.
79+
- name: Run lifecycle tests
80+
if: ${{ (matrix.oci_bin == 'docker') && (matrix.command == 'lifecycle') }}
81+
run: |
82+
make run-on-kind && make test-lifecycle-local
83+
7184
- name: Check disk space
7285
run: df -h
7386

Makefile

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,7 @@ test: fmt envtest ## Run Unit tests.
303303

304304

305305
.PHONY: test-integration
306-
test-integration: ## Run Integration tests.
307-
cd config/bpfman-deployment && \
308-
$(SED) -e 's@bpfman\.image=.*@bpfman.image=$(BPFMAN_IMG)@' \
309-
-e 's@bpfman\.agent\.image=.*@bpfman.agent.image=$(BPFMAN_AGENT_IMG)@' \
310-
kustomization.yaml.env > kustomization.yaml
306+
test-integration: patch-image-references ## Run Integration tests.
311307
GOFLAGS="-tags=integration_tests" go test -count=1 -race -v ./test/integration/...
312308

313309
.PHONY: test-integration-local
@@ -316,17 +312,16 @@ test-integration-local: ## Run Integration tests against existing deployment. Us
316312
SKIP_BPFMAN_DEPLOY=true \
317313
GOFLAGS="-tags=integration_tests" go test -count=1 -race -v ./test/integration $(if $(TEST),-run $(TEST),)
318314

315+
.PHONY: test-lifecycle-local
316+
test-lifecycle-local: ## Run lifecycle tests against existing deployment.
317+
GOFLAGS="-tags=integration_tests" go test -count=1 -race -v ./test/lifecycle
318+
319319
## The physical bundle is no longer tracked in git since it should be considered
320320
## and treated as a release artifact, rather than something that's updated
321321
## as part of a pull request.
322322
## See https://github.com/operator-framework/operator-sdk/issues/6285.
323323
.PHONY: bundle
324-
bundle: operator-sdk generate kustomize manifests ## Generate bundle manifests and metadata, then validate generated files.
325-
cd config/bpfman-operator-deployment && $(KUSTOMIZE) edit set image quay.io/bpfman/bpfman-operator=${BPFMAN_OPERATOR_IMG}
326-
cd config/bpfman-deployment && \
327-
$(SED) -e 's@bpfman\.image=.*@bpfman.image=$(BPFMAN_IMG)@' \
328-
-e 's@bpfman\.agent\.image=.*@bpfman.agent.image=$(BPFMAN_AGENT_IMG)@' \
329-
kustomization.yaml.env > kustomization.yaml
324+
bundle: operator-sdk generate kustomize manifests patch-image-references ## Generate bundle manifests and metadata, then validate generated files.
330325
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
331326
# Dependency on security-profiles-operator removed (file renamed to dependencies.yaml.disabled)
332327
# https://github.com/kubernetes-sigs/security-profiles-operator/issues/2699
@@ -439,6 +434,16 @@ install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~
439434
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
440435
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
441436

437+
##@ Image Patching
438+
439+
.PHONY: patch-image-references
440+
patch-image-references: kustomize ## Update all image references with environment variables
441+
cd config/bpfman-operator-deployment && $(KUSTOMIZE) edit set image quay.io/bpfman/bpfman-operator=${BPFMAN_OPERATOR_IMG}
442+
cd config/bpfman-deployment && \
443+
$(SED) -e '[email protected]/bpfman/bpfman:latest@$(BPFMAN_IMG)@g' \
444+
-e '[email protected]/bpfman/bpfman-agent:latest@$(BPFMAN_AGENT_IMG)@g' \
445+
kustomization.yaml.env > kustomization.yaml
446+
442447
##@ Vanilla K8s Deployment
443448

444449
.PHONY: setup-kind
@@ -451,44 +456,38 @@ destroy-kind: ## Destroy Kind cluster
451456

452457
## Default deploy target is KIND based with its CSI driver initialized.
453458
.PHONY: deploy
454-
deploy: manifests kustomize ## Deploy bpfman-operator to the K8s cluster specified in ~/.kube/config with the csi driver initialized.
455-
cd config/bpfman-operator-deployment && $(KUSTOMIZE) edit set image quay.io/bpfman/bpfman-operator=${BPFMAN_OPERATOR_IMG}
456-
cd config/bpfman-deployment && \
457-
$(SED) -e 's@bpfman\.image=.*@bpfman.image=$(BPFMAN_IMG)@' \
458-
-e 's@bpfman\.agent\.image=.*@bpfman.agent.image=$(BPFMAN_AGENT_IMG)@' \
459-
kustomization.yaml.env > kustomization.yaml
459+
deploy: install patch-image-references ## Deploy bpfman-operator to the K8s cluster specified in ~/.kube/config with the csi driver initialized.
460460
$(KUSTOMIZE) build config/default | kubectl apply -f -
461461

462462
.PHONY: undeploy
463-
undeploy: ## Undeploy bpfman-operator from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
464-
kubectl delete --ignore-not-found=$(ignore-not-found) cm bpfman-config -n bpfman
465-
kubectl wait --for=delete configmap/bpfman-config -n bpfman --timeout=60s
466-
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
463+
undeploy: kustomize ## Undeploy bpfman-operator from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
464+
@if kubectl get crd configs.bpfman.io >/dev/null 2>&1; then \
465+
kubectl delete --ignore-not-found=$(ignore-not-found) configs.bpfman.io bpfman-config; \
466+
kubectl wait --for=delete configs.bpfman.io/bpfman-config --timeout=60s; \
467+
fi
468+
-$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
467469

468470
.PHONY: kind-reload-images
469471
kind-reload-images: load-images-kind ## Reload locally build images into a kind cluster and restart the ds and deployment so they're picked up.
470472
kubectl rollout restart daemonset bpfman-daemon -n bpfman
471473
kubectl rollout restart deployment bpfman-operator -n bpfman
472474

473475
.PHONY: run-on-kind
474-
run-on-kind: kustomize setup-kind build-images load-images-kind deploy ## Kind Deploy runs the bpfman-operator on a local kind cluster using local builds of bpfman, bpfman-agent, and bpfman-operator
476+
run-on-kind: kustomize setup-kind build-images load-images-kind install deploy ## Kind Deploy runs the bpfman-operator on a local kind cluster using local builds of bpfman, bpfman-agent, and bpfman-operator
475477

476478
##@ Openshift Deployment
477479

478480
.PHONY: deploy-openshift
479-
deploy-openshift: manifests kustomize ## Deploy bpfman-operator to the Openshift cluster specified in ~/.kube/config.
480-
cd config/bpfman-operator-deployment && $(KUSTOMIZE) edit set image quay.io/bpfman/bpfman-operator=${BPFMAN_OPERATOR_IMG}
481-
cd config/bpfman-deployment && \
482-
$(SED) -e 's@bpfman\.image=.*@bpfman.image=$(BPFMAN_IMG)@' \
483-
-e 's@bpfman\.agent\.image=.*@bpfman.agent.image=$(BPFMAN_AGENT_IMG)@' \
484-
kustomization.yaml.env > kustomization.yaml
481+
deploy-openshift: install patch-image-references ## Deploy bpfman-operator to the Openshift cluster specified in ~/.kube/config.
485482
$(KUSTOMIZE) build config/openshift | kubectl apply -f -
486483

487484
.PHONY: undeploy-openshift
488-
undeploy-openshift: ## Undeploy bpfman-operator from the Openshift cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
489-
kubectl delete --ignore-not-found=$(ignore-not-found) cm bpfman-config -n bpfman
490-
kubectl wait --for=delete configmap/bpfman-config -n bpfman --timeout=60s
491-
$(KUSTOMIZE) build config/openshift | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
485+
undeploy-openshift: kustomize ## Undeploy bpfman-operator from the Openshift cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
486+
@if kubectl get crd configs.bpfman.io >/dev/null 2>&1; then \
487+
kubectl delete --ignore-not-found=$(ignore-not-found) configs.bpfman.io bpfman-config; \
488+
kubectl wait --for=delete configs.bpfman.io/bpfman-config --timeout=60s; \
489+
fi
490+
-$(KUSTOMIZE) build config/openshift | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
492491

493492
# Deploy the catalog.
494493
.PHONY: catalog-deploy

apis/v1alpha1/config_types.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
Copyright 2023 The bpfman Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// +genclient
24+
// +genclient:nonNamespaced
25+
// +kubebuilder:object:root=true
26+
// +kubebuilder:subresource:status
27+
// +kubebuilder:resource:scope=Cluster
28+
29+
// Config holds the configuration for bpfman-operator.
30+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
31+
type Config struct {
32+
metav1.TypeMeta `json:",inline"`
33+
metav1.ObjectMeta `json:"metadata,omitempty"`
34+
35+
Spec ConfigSpec `json:"spec,omitempty"`
36+
Status ConfigStatus `json:"status,omitempty"`
37+
}
38+
39+
// Spec defines the desired state of the bpfman-operator.
40+
type ConfigSpec struct {
41+
// Agent holds the configuration for the bpfman agent.
42+
// +required
43+
Agent AgentSpec `json:"agent,omitempty"`
44+
// Configuration holds the content of bpfman.toml.
45+
// +required
46+
// +kubebuilder:validation:Required
47+
// +kubebuilder:validation:MinLength=1
48+
Configuration string `json:"configuration"`
49+
// Image holds the image of the bpfman DaemonSets.
50+
// +required
51+
// +kubebuilder:validation:Required
52+
// +kubebuilder:validation:MinLength=1
53+
Image string `json:"image"`
54+
// LogLevel holds the log level for the bpfman-operator.
55+
// +optional
56+
LogLevel string `json:"logLevel,omitempty"`
57+
// Namespace holds the namespace where bpfman-operator resources shall be
58+
// deployed.
59+
Namespace string `json:"namespace,omitempty"`
60+
}
61+
62+
// AgentSpec defines the desired state of the bpfman agent.
63+
type AgentSpec struct {
64+
// HealthProbePort holds the health probe bind port for the bpfman agent.
65+
// +optional
66+
// +kubebuilder:default=8175
67+
// +kubebuilder:validation:Minimum=1
68+
// +kubebuilder:validation:Maximum=65535
69+
HealthProbePort int `json:"healthProbeAddr"`
70+
// Image holds the image for the bpfman agent.
71+
// +required
72+
// +kubebuilder:validation:Required
73+
// +kubebuilder:validation:MinLength=1
74+
Image string `json:"image"`
75+
// LogLevel holds the log level for the bpfman agent.
76+
// +optional
77+
LogLevel string `json:"logLevel,omitempty"`
78+
}
79+
80+
// status reflects the status of the bpfman-operator configuration.
81+
type ConfigStatus struct {
82+
// conditions store the status conditions of the bpfman-operator.
83+
// +patchMergeKey=type
84+
// +patchStrategy=merge
85+
// +listType=map
86+
// +listMapKey=type
87+
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
88+
}
89+
90+
// +kubebuilder:object:root=true
91+
// ConfigList contains a list of Configs.
92+
type ConfigList struct {
93+
metav1.TypeMeta `json:",inline"`
94+
metav1.ListMeta `json:"metadata,omitempty"`
95+
Items []Config `json:"items"`
96+
}

apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 112 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/zz_generated.register.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)