From b15cc21510940f3e2f56e8602cf4cd4f90afc98f Mon Sep 17 00:00:00 2001 From: Vibhu Prashar Date: Fri, 14 Jun 2024 17:08:38 +0530 Subject: [PATCH] feat: migrate operator code base to support new operator-sdk version This PR updates the code base for compatibility with the latest operator-sdk version(v1.35.0) Key Changes: * Moved API files from `pkg/api` to `api` folder * Relocated `main.go` from `cmd/manager/main.go` to `cmd/main.go` * Shifted controllers from `pkg/controllers` to `controllers` folder * Made minor updates to components, utils and tests to use correct import paths * Updated scaffolding config to align with the latest operator-sdk version * Revised Operator, bundle and e2e Dockerfiles * Upgraded operator-sdk to v1.35.0 and controller-gen to v0.13.0 * Updated bundle manifests accordingly Signed-off-by: Vibhu Prashar --- Dockerfile | 22 +-- Makefile | 8 +- PROJECT | 7 +- .../api => api}/v1alpha1/groupversion_info.go | 2 +- .../v1alpha1/kepler_internal_types.go | 2 +- {pkg/api => api}/v1alpha1/kepler_types.go | 2 +- {pkg/api => api}/v1alpha1/kepler_webhook.go | 2 +- .../v1alpha1/zz_generated.deepcopy.go | 3 +- bundle.Dockerfile | 4 +- ...kepler-operator.clusterserviceversion.yaml | 36 ++++- ...tainable.computing.io_keplerinternals.yaml | 2 +- ...stem.sustainable.computing.io_keplers.yaml | 2 +- bundle/metadata/annotations.yaml | 4 +- bundle/tests/scorecard/config.yaml | 12 +- cmd/{manager => }/main.go | 4 +- config/certmanager/certificate.yaml | 10 +- config/certmanager/kustomizeconfig.yaml | 10 +- ...tainable.computing.io_keplerinternals.yaml | 2 +- ...stem.sustainable.computing.io_keplers.yaml | 2 +- config/crd/kustomization.yaml | 8 +- .../crd/patches/cainjection_in_keplers.yaml | 2 +- config/default/kustomization.yaml | 144 +++++++++++++----- config/default/manager_auth_proxy_patch.yaml | 4 +- config/default/manager_webhook_patch.yaml | 12 +- config/default/webhookcainjection_patch.yaml | 6 +- config/manager/kustomization.yaml | 6 - config/manifests/kustomization.yaml | 10 +- config/prometheus/monitor.yaml | 13 +- config/rbac/auth_proxy_service.yaml | 9 ++ config/rbac/role.yaml | 26 ++++ config/rbac/service_account.yaml | 2 +- config/scorecard/patches/basic.config.yaml | 2 +- config/scorecard/patches/olm.config.yaml | 10 +- config/webhook/kustomizeconfig.yaml | 5 +- config/webhook/service.yaml | 3 + {pkg/controllers => controllers}/config.go | 0 {pkg/controllers => controllers}/kepler.go | 2 +- .../kepler_internal.go | 2 +- .../reconcilers.go | 0 go.mod | 5 + go.sum | 6 + hack/boilerplate.go.txt | 4 +- hack/bundle.sh | 2 +- hack/tools.sh | 4 +- internal/controller/kepler_controller.go | 62 ++++++++ internal/controller/kepler_controller_test.go | 84 ++++++++++ internal/controller/suite_test.go | 90 +++++++++++ pkg/components/estimator/estimator.go | 2 +- pkg/components/estimator/estimator_test.go | 2 +- pkg/components/exporter/exporter.go | 2 +- pkg/components/exporter/exporter_test.go | 2 +- pkg/components/modelserver/modelserver.go | 2 +- .../modelserver/modelserver_test.go | 2 +- pkg/reconciler/kepler.go | 2 +- pkg/utils/k8s/k8s.go | 2 +- pkg/utils/test/assertions.go | 2 +- pkg/utils/test/framework.go | 2 +- pkg/utils/test/kepler_internal_builder.go | 2 +- tests/Dockerfile | 8 +- tests/e2e/kepler_internal_test.go | 4 +- tests/e2e/kepler_test.go | 4 +- tests/e2e/main_test.go | 2 +- 62 files changed, 540 insertions(+), 159 deletions(-) rename {pkg/api => api}/v1alpha1/groupversion_info.go (98%) rename {pkg/api => api}/v1alpha1/kepler_internal_types.go (99%) rename {pkg/api => api}/v1alpha1/kepler_types.go (99%) rename {pkg/api => api}/v1alpha1/kepler_webhook.go (99%) rename {pkg/api => api}/v1alpha1/zz_generated.deepcopy.go (99%) rename cmd/{manager => }/main.go (98%) rename {pkg/controllers => controllers}/config.go (100%) rename {pkg/controllers => controllers}/kepler.go (99%) rename {pkg/controllers => controllers}/kepler_internal.go (99%) rename {pkg/controllers => controllers}/reconcilers.go (100%) create mode 100644 internal/controller/kepler_controller.go create mode 100644 internal/controller/kepler_controller_test.go create mode 100644 internal/controller/suite_test.go diff --git a/Dockerfile b/Dockerfile index ec44c8e2..899a9cba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Build the manager binary -FROM golang:1.21 as builder +FROM golang:1.21 AS builder ARG TARGETOS ARG TARGETARCH @@ -12,10 +12,14 @@ COPY go.sum go.sum RUN go mod download # Copy the go source -COPY must-gather/ must-gather/ -COPY cmd/ cmd/ +COPY cmd/main.go cmd/main.go +COPY api/ api/ COPY pkg/ pkg/ +COPY controllers/ controllers/ + +# Copy must-gather scripts +COPY must-gather/ must-gather/ # Build # the GOARCH has not a default value to allow the binary be built according to the host where the command @@ -23,17 +27,17 @@ COPY pkg/ pkg/ # the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore, # by leaving it empty we can ensure that the container and binary shipped on it will have the same platform. RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} \ - go build -a -o manager ./cmd/manager/... + go build -a -o manager cmd/main.go FROM quay.io/openshift/origin-cli:4.13 AS origincli FROM registry.access.redhat.com/ubi9-minimal:9.2 RUN INSTALL_PKGS=" \ - rsync \ - tar \ - " && \ - microdnf install -y $INSTALL_PKGS && \ - microdnf clean all + rsync \ + tar \ + " && \ + microdnf install -y $INSTALL_PKGS && \ + microdnf clean all WORKDIR / COPY --from=builder /workspace/manager . COPY --from=builder /workspace/must-gather/* /usr/bin/ diff --git a/Makefile b/Makefile index 078bc1fb..efd7f3fe 100644 --- a/Makefile +++ b/Makefile @@ -89,11 +89,11 @@ help: ## Display this help. .PHONY: manifests manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. - $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./pkg/..." output:crd:artifacts:config=config/crd/bases + $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases .PHONY: generate generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. - $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./pkg/..." + $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." .PHONY: fmt fmt: shfmt ## Run go fmt against code. @@ -153,14 +153,14 @@ cluster-down: ## delete the local development cluster .PHONY: build build: manifests generate fmt vet ## Build manager binary. - go build -o bin/manager ./cmd/manager/... + go build -o bin/manager ./cmd/... OPENSHIFT ?= true RUN_ARGS ?= .PHONY: run run: install fmt vet ## Run a controller from your host against openshift cluster - go run ./cmd/manager/... \ + go run ./cmd/... \ --kepler.image=$(KEPLER_IMG) \ --zap-devel --zap-log-level=8 \ --openshift=$(OPENSHIFT) \ diff --git a/PROJECT b/PROJECT index 8625b9a3..c1587ef4 100644 --- a/PROJECT +++ b/PROJECT @@ -1,6 +1,10 @@ +# Code generated by tool. DO NOT EDIT. +# This file is used to track the info used to scaffold your project +# and allow the plugins properly work. +# More info: https://book.kubebuilder.io/reference/project-config.html domain: sustainable.computing.io layout: -- go.kubebuilder.io/v3 +- go.kubebuilder.io/v4 plugins: manifests.sdk.operatorframework.io/v2: {} scorecard.sdk.operatorframework.io/v2: {} @@ -9,6 +13,7 @@ repo: github.com/sustainable.computing.io/kepler-operator resources: - api: crdVersion: v1 + namespaced: true controller: true domain: sustainable.computing.io group: kepler.system diff --git a/pkg/api/v1alpha1/groupversion_info.go b/api/v1alpha1/groupversion_info.go similarity index 98% rename from pkg/api/v1alpha1/groupversion_info.go rename to api/v1alpha1/groupversion_info.go index fb0ebeca..667763b2 100644 --- a/pkg/api/v1alpha1/groupversion_info.go +++ b/api/v1alpha1/groupversion_info.go @@ -1,5 +1,5 @@ /* -Copyright 2022. +Copyright 2024. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/pkg/api/v1alpha1/kepler_internal_types.go b/api/v1alpha1/kepler_internal_types.go similarity index 99% rename from pkg/api/v1alpha1/kepler_internal_types.go rename to api/v1alpha1/kepler_internal_types.go index 771f598b..12fab21d 100644 --- a/pkg/api/v1alpha1/kepler_internal_types.go +++ b/api/v1alpha1/kepler_internal_types.go @@ -1,5 +1,5 @@ /* -Copyright 2023. +Copyright 2024. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/pkg/api/v1alpha1/kepler_types.go b/api/v1alpha1/kepler_types.go similarity index 99% rename from pkg/api/v1alpha1/kepler_types.go rename to api/v1alpha1/kepler_types.go index 21d5a274..dfd5b040 100644 --- a/pkg/api/v1alpha1/kepler_types.go +++ b/api/v1alpha1/kepler_types.go @@ -1,5 +1,5 @@ /* -Copyright 2022. +Copyright 2024. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/pkg/api/v1alpha1/kepler_webhook.go b/api/v1alpha1/kepler_webhook.go similarity index 99% rename from pkg/api/v1alpha1/kepler_webhook.go rename to api/v1alpha1/kepler_webhook.go index e5dd6bdb..73932024 100644 --- a/pkg/api/v1alpha1/kepler_webhook.go +++ b/api/v1alpha1/kepler_webhook.go @@ -1,5 +1,5 @@ /* -Copyright 2023. +Copyright 2024. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/pkg/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go similarity index 99% rename from pkg/api/v1alpha1/zz_generated.deepcopy.go rename to api/v1alpha1/zz_generated.deepcopy.go index 621fce09..a6b05cf4 100644 --- a/pkg/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -1,8 +1,7 @@ //go:build !ignore_autogenerated -// +build !ignore_autogenerated /* -Copyright 2023. +Copyright 2024. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/bundle.Dockerfile b/bundle.Dockerfile index 57eda2d3..0797a508 100644 --- a/bundle.Dockerfile +++ b/bundle.Dockerfile @@ -7,9 +7,9 @@ LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ LABEL operators.operatorframework.io.bundle.package.v1=kepler-operator LABEL operators.operatorframework.io.bundle.channels.v1=alpha LABEL operators.operatorframework.io.bundle.channel.default.v1=alpha -LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.27.0 +LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.35.0 LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1 -LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3 +LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v4 # Labels for testing. LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1 diff --git a/bundle/manifests/kepler-operator.clusterserviceversion.yaml b/bundle/manifests/kepler-operator.clusterserviceversion.yaml index f24e15fd..93b2f143 100644 --- a/bundle/manifests/kepler-operator.clusterserviceversion.yaml +++ b/bundle/manifests/kepler-operator.clusterserviceversion.yaml @@ -28,14 +28,14 @@ metadata: capabilities: Seamless Upgrades categories: Monitoring containerImage: quay.io/sustainable_computing_io/kepler-operator:0.13.0 - createdAt: "2024-05-22T07:06:13Z" + createdAt: "2024-06-25T06:01:26Z" description: 'Deploys and Manages Kepler on Kubernetes ' - operators.operatorframework.io/builder: operator-sdk-v1.27.0 + operators.operatorframework.io/builder: operator-sdk-v1.35.0 operators.operatorframework.io/internal-objects: |- [ "keplerinternals.kepler.system.sustainable.computing.io" ] - operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 + operators.operatorframework.io/project_layout: go.kubebuilder.io/v4 repository: https://github.com/sustainable-computing-io/kepler-operator support: https://github.com/sustainable-computing-io/kepler-operator/issues name: kepler-operator.v0.13.0 @@ -173,6 +173,32 @@ spec: - '*' verbs: - '*' + - apiGroups: + - kepler.system.sustainable.computing.io + resources: + - keplers + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - kepler.system.sustainable.computing.io + resources: + - keplers/finalizers + verbs: + - update + - apiGroups: + - kepler.system.sustainable.computing.io + resources: + - keplers/status + verbs: + - get + - patch + - update - apiGroups: - monitoring.coreos.com resources: @@ -302,10 +328,6 @@ spec: capabilities: drop: - ALL - volumeMounts: - - mountPath: /tmp/k8s-webhook-server/serving-certs - name: cert - readOnly: true securityContext: runAsNonRoot: true serviceAccountName: kepler-operator-controller-manager diff --git a/bundle/manifests/kepler.system.sustainable.computing.io_keplerinternals.yaml b/bundle/manifests/kepler.system.sustainable.computing.io_keplerinternals.yaml index cb3685db..b860052b 100644 --- a/bundle/manifests/kepler.system.sustainable.computing.io_keplerinternals.yaml +++ b/bundle/manifests/kepler.system.sustainable.computing.io_keplerinternals.yaml @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.12.1 + controller-gen.kubebuilder.io/version: v0.13.0 creationTimestamp: null name: keplerinternals.kepler.system.sustainable.computing.io spec: diff --git a/bundle/manifests/kepler.system.sustainable.computing.io_keplers.yaml b/bundle/manifests/kepler.system.sustainable.computing.io_keplers.yaml index dbe4039e..464ce774 100644 --- a/bundle/manifests/kepler.system.sustainable.computing.io_keplers.yaml +++ b/bundle/manifests/kepler.system.sustainable.computing.io_keplers.yaml @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.12.1 + controller-gen.kubebuilder.io/version: v0.13.0 creationTimestamp: null name: keplers.kepler.system.sustainable.computing.io spec: diff --git a/bundle/metadata/annotations.yaml b/bundle/metadata/annotations.yaml index 6c3ba580..463c9587 100644 --- a/bundle/metadata/annotations.yaml +++ b/bundle/metadata/annotations.yaml @@ -6,9 +6,9 @@ annotations: operators.operatorframework.io.bundle.package.v1: kepler-operator operators.operatorframework.io.bundle.channels.v1: alpha operators.operatorframework.io.bundle.channel.default.v1: alpha - operators.operatorframework.io.metrics.builder: operator-sdk-v1.27.0 + operators.operatorframework.io.metrics.builder: operator-sdk-v1.35.0 operators.operatorframework.io.metrics.mediatype.v1: metrics+v1 - operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v3 + operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v4 # Annotations for testing. operators.operatorframework.io.test.mediatype.v1: scorecard+v1 diff --git a/bundle/tests/scorecard/config.yaml b/bundle/tests/scorecard/config.yaml index 8b5e5cff..4e32de13 100644 --- a/bundle/tests/scorecard/config.yaml +++ b/bundle/tests/scorecard/config.yaml @@ -8,7 +8,7 @@ stages: - entrypoint: - scorecard-test - basic-check-spec - image: quay.io/operator-framework/scorecard-test:v1.25.1 + image: quay.io/operator-framework/scorecard-test:v1.35.0 labels: suite: basic test: basic-check-spec-test @@ -18,7 +18,7 @@ stages: - entrypoint: - scorecard-test - olm-bundle-validation - image: quay.io/operator-framework/scorecard-test:v1.25.1 + image: quay.io/operator-framework/scorecard-test:v1.35.0 labels: suite: olm test: olm-bundle-validation-test @@ -28,7 +28,7 @@ stages: - entrypoint: - scorecard-test - olm-crds-have-validation - image: quay.io/operator-framework/scorecard-test:v1.25.1 + image: quay.io/operator-framework/scorecard-test:v1.35.0 labels: suite: olm test: olm-crds-have-validation-test @@ -38,7 +38,7 @@ stages: - entrypoint: - scorecard-test - olm-crds-have-resources - image: quay.io/operator-framework/scorecard-test:v1.25.1 + image: quay.io/operator-framework/scorecard-test:v1.35.0 labels: suite: olm test: olm-crds-have-resources-test @@ -48,7 +48,7 @@ stages: - entrypoint: - scorecard-test - olm-spec-descriptors - image: quay.io/operator-framework/scorecard-test:v1.25.1 + image: quay.io/operator-framework/scorecard-test:v1.35.0 labels: suite: olm test: olm-spec-descriptors-test @@ -58,7 +58,7 @@ stages: - entrypoint: - scorecard-test - olm-status-descriptors - image: quay.io/operator-framework/scorecard-test:v1.25.1 + image: quay.io/operator-framework/scorecard-test:v1.35.0 labels: suite: olm test: olm-status-descriptors-test diff --git a/cmd/manager/main.go b/cmd/main.go similarity index 98% rename from cmd/manager/main.go rename to cmd/main.go index 7206982f..852fefd0 100644 --- a/cmd/manager/main.go +++ b/cmd/main.go @@ -39,11 +39,11 @@ import ( securityv1 "github.com/openshift/api/security/v1" - keplersystemv1alpha1 "github.com/sustainable.computing.io/kepler-operator/pkg/api/v1alpha1" + keplersystemv1alpha1 "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" + "github.com/sustainable.computing.io/kepler-operator/controllers" "github.com/sustainable.computing.io/kepler-operator/pkg/components/estimator" "github.com/sustainable.computing.io/kepler-operator/pkg/components/exporter" "github.com/sustainable.computing.io/kepler-operator/pkg/components/modelserver" - "github.com/sustainable.computing.io/kepler-operator/pkg/controllers" "github.com/sustainable.computing.io/kepler-operator/pkg/utils/k8s" //+kubebuilder:scaffold:imports ) diff --git a/config/certmanager/certificate.yaml b/config/certmanager/certificate.yaml index 92b36798..97189b7d 100644 --- a/config/certmanager/certificate.yaml +++ b/config/certmanager/certificate.yaml @@ -5,8 +5,8 @@ apiVersion: cert-manager.io/v1 kind: Issuer metadata: labels: - app.kubernetes.io/name: issuer - app.kubernetes.io/instance: selfsigned-issuer + app.kubernetes.io/name: certificate + app.kubernetes.io/instance: serving-cert app.kubernetes.io/component: certificate app.kubernetes.io/created-by: kepler-operator app.kubernetes.io/part-of: kepler-operator @@ -29,10 +29,10 @@ metadata: name: serving-cert # this name should match the one appeared in kustomizeconfig.yaml namespace: system spec: - # $(SERVICE_NAME) and $(SERVICE_NAMESPACE) will be substituted by kustomize + # SERVICE_NAME and SERVICE_NAMESPACE will be substituted by kustomize dnsNames: - - $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc - - $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc.cluster.local + - SERVICE_NAME.SERVICE_NAMESPACE.svc + - SERVICE_NAME.SERVICE_NAMESPACE.svc.cluster.local issuerRef: kind: Issuer name: selfsigned-issuer diff --git a/config/certmanager/kustomizeconfig.yaml b/config/certmanager/kustomizeconfig.yaml index 90d7c313..cf6f89e8 100644 --- a/config/certmanager/kustomizeconfig.yaml +++ b/config/certmanager/kustomizeconfig.yaml @@ -1,4 +1,4 @@ -# This configuration is for teaching kustomize how to update name ref and var substitution +# This configuration is for teaching kustomize how to update name ref substitution nameReference: - kind: Issuer group: cert-manager.io @@ -6,11 +6,3 @@ nameReference: - kind: Certificate group: cert-manager.io path: spec/issuerRef/name - -varReference: -- kind: Certificate - group: cert-manager.io - path: spec/commonName -- kind: Certificate - group: cert-manager.io - path: spec/dnsNames diff --git a/config/crd/bases/kepler.system.sustainable.computing.io_keplerinternals.yaml b/config/crd/bases/kepler.system.sustainable.computing.io_keplerinternals.yaml index 91d7cca5..6c20ccd7 100644 --- a/config/crd/bases/kepler.system.sustainable.computing.io_keplerinternals.yaml +++ b/config/crd/bases/kepler.system.sustainable.computing.io_keplerinternals.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.12.1 + controller-gen.kubebuilder.io/version: v0.13.0 name: keplerinternals.kepler.system.sustainable.computing.io spec: group: kepler.system.sustainable.computing.io diff --git a/config/crd/bases/kepler.system.sustainable.computing.io_keplers.yaml b/config/crd/bases/kepler.system.sustainable.computing.io_keplers.yaml index e48146b0..cf468d7f 100644 --- a/config/crd/bases/kepler.system.sustainable.computing.io_keplers.yaml +++ b/config/crd/bases/kepler.system.sustainable.computing.io_keplers.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.12.1 + controller-gen.kubebuilder.io/version: v0.13.0 name: keplers.kepler.system.sustainable.computing.io spec: group: kepler.system.sustainable.computing.io diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index 4d4f6536..3ebf9edd 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -6,17 +6,19 @@ resources: - bases/kepler.system.sustainable.computing.io_keplerinternals.yaml #+kubebuilder:scaffold:crdkustomizeresource -patchesStrategicMerge: +patches: # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix. # patches here are for enabling the conversion webhook for each CRD -- patches/webhook_in_keplers.yaml +- path: patches/webhook_in_keplers.yaml #+kubebuilder:scaffold:crdkustomizewebhookpatch # [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix. # patches here are for enabling the CA injection for each CRD -#- patches/cainjection_in_keplers.yaml +#- path: patches/cainjection_in_keplers.yaml #+kubebuilder:scaffold:crdkustomizecainjectionpatch +# [WEBHOOK] To enable webhook, uncomment the following section # the following config is for teaching kustomize how to do kustomization for CRDs. + configurations: - kustomizeconfig.yaml diff --git a/config/crd/patches/cainjection_in_keplers.yaml b/config/crd/patches/cainjection_in_keplers.yaml index 43a013b5..cec037e1 100644 --- a/config/crd/patches/cainjection_in_keplers.yaml +++ b/config/crd/patches/cainjection_in_keplers.yaml @@ -3,5 +3,5 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) + cert-manager.io/inject-ca-from: CERTIFICATE_NAMESPACE/CERTIFICATE_NAME name: keplers.kepler.system.sustainable.computing.io diff --git a/config/default/kustomization.yaml b/config/default/kustomization.yaml index fa298e61..886a355e 100644 --- a/config/default/kustomization.yaml +++ b/config/default/kustomization.yaml @@ -9,10 +9,12 @@ namespace: kepler-operator-system namePrefix: kepler-operator- # Labels to add to all resources and selectors. -#commonLabels: -# someName: someValue +#labels: +#- includeSelectors: true +# pairs: +# someName: someValue -bases: +resources: - ../crd - ../rbac - ../manager @@ -24,49 +26,117 @@ bases: # [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'. - ../prometheus -patchesStrategicMerge: +patches: # Protect the /metrics endpoint by putting it behind auth. # If you want your controller-manager to expose the /metrics # endpoint w/o any authn/z, please comment the following line. -# - manager_auth_proxy_patch.yaml - - +# - path: manager_auth_proxy_patch.yaml # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in # crd/kustomization.yaml -- manager_webhook_patch.yaml +- path: manager_webhook_patch.yaml # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. # Uncomment 'CERTMANAGER' sections in crd/kustomization.yaml to enable the CA injection in the admission webhooks. # 'CERTMANAGER' needs to be enabled to use ca injection -#- webhookcainjection_patch.yaml +#- path: webhookcainjection_patch.yaml -# the following config is for teaching kustomize how to do var substitution -vars: # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix. -#- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR -# objref: -# kind: Certificate -# group: cert-manager.io -# version: v1 -# name: serving-cert # this name should match the one in certificate.yaml -# fieldref: -# fieldpath: metadata.namespace -#- name: CERTIFICATE_NAME -# objref: -# kind: Certificate -# group: cert-manager.io -# version: v1 -# name: serving-cert # this name should match the one in certificate.yaml -#- name: SERVICE_NAMESPACE # namespace of the service -# objref: -# kind: Service -# version: v1 -# name: webhook-service -# fieldref: -# fieldpath: metadata.namespace -#- name: SERVICE_NAME -# objref: -# kind: Service -# version: v1 -# name: webhook-service +# Uncomment the following replacements to add the cert-manager CA injection annotations +#replacements: +# - source: # Add cert-manager annotation to ValidatingWebhookConfiguration, MutatingWebhookConfiguration and CRDs +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert # this name should match the one in certificate.yaml +# fieldPath: .metadata.namespace # namespace of the certificate CR +# targets: +# - select: +# kind: ValidatingWebhookConfiguration +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 0 +# create: true +# - select: +# kind: MutatingWebhookConfiguration +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 0 +# create: true +# - select: +# kind: CustomResourceDefinition +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 0 +# create: true +# - source: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# name: serving-cert # this name should match the one in certificate.yaml +# fieldPath: .metadata.name +# targets: +# - select: +# kind: ValidatingWebhookConfiguration +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 1 +# create: true +# - select: +# kind: MutatingWebhookConfiguration +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 1 +# create: true +# - select: +# kind: CustomResourceDefinition +# fieldPaths: +# - .metadata.annotations.[cert-manager.io/inject-ca-from] +# options: +# delimiter: '/' +# index: 1 +# create: true +# - source: # Add cert-manager annotation to the webhook Service +# kind: Service +# version: v1 +# name: webhook-service +# fieldPath: .metadata.name # namespace of the service +# targets: +# - select: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# fieldPaths: +# - .spec.dnsNames.0 +# - .spec.dnsNames.1 +# options: +# delimiter: '.' +# index: 0 +# create: true +# - source: +# kind: Service +# version: v1 +# name: webhook-service +# fieldPath: .metadata.namespace # namespace of the service +# targets: +# - select: +# kind: Certificate +# group: cert-manager.io +# version: v1 +# fieldPaths: +# - .spec.dnsNames.0 +# - .spec.dnsNames.1 +# options: +# delimiter: '.' +# index: 1 +# create: true diff --git a/config/default/manager_auth_proxy_patch.yaml b/config/default/manager_auth_proxy_patch.yaml index f07d69d9..a74efc72 100644 --- a/config/default/manager_auth_proxy_patch.yaml +++ b/config/default/manager_auth_proxy_patch.yaml @@ -30,8 +30,8 @@ spec: allowPrivilegeEscalation: false capabilities: drop: - - "ALL" - image: gcr.io/kubebuilder/kube-rbac-proxy:v0.13.0 + - "ALL" + image: gcr.io/kubebuilder/kube-rbac-proxy:v0.15.0 args: - "--secure-listen-address=0.0.0.0:8443" - "--upstream=http://127.0.0.1:8080/" diff --git a/config/default/manager_webhook_patch.yaml b/config/default/manager_webhook_patch.yaml index 1c378047..349289c3 100644 --- a/config/default/manager_webhook_patch.yaml +++ b/config/default/manager_webhook_patch.yaml @@ -16,10 +16,8 @@ spec: - mountPath: /tmp/k8s-webhook-server/serving-certs name: cert readOnly: true - # NOTE: this will be removed by the manager kustomization.yaml - # since OLM will add the volume - volumes: - - name: cert - secret: - defaultMode: 420 - secretName: webhook-server-cert + volumes: + - name: cert + secret: + defaultMode: 420 + secretName: webhook-server-cert diff --git a/config/default/webhookcainjection_patch.yaml b/config/default/webhookcainjection_patch.yaml index f992f958..6b105181 100644 --- a/config/default/webhookcainjection_patch.yaml +++ b/config/default/webhookcainjection_patch.yaml @@ -1,5 +1,5 @@ # This patch add annotation to admission webhook config and -# the variables $(CERTIFICATE_NAMESPACE) and $(CERTIFICATE_NAME) will be substituted by kustomize. +# CERTIFICATE_NAMESPACE and CERTIFICATE_NAME will be substituted by kustomize apiVersion: admissionregistration.k8s.io/v1 kind: MutatingWebhookConfiguration metadata: @@ -12,7 +12,7 @@ metadata: app.kubernetes.io/managed-by: kustomize name: mutating-webhook-configuration annotations: - cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) + cert-manager.io/inject-ca-from: CERTIFICATE_NAMESPACE/CERTIFICATE_NAME --- apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration @@ -26,4 +26,4 @@ metadata: app.kubernetes.io/managed-by: kustomize name: validating-webhook-configuration annotations: - cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) + cert-manager.io/inject-ca-from: CERTIFICATE_NAMESPACE/CERTIFICATE_NAME diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 866f427e..5c5f0b84 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,8 +1,2 @@ resources: - manager.yaml -apiVersion: kustomize.config.k8s.io/v1beta1 -kind: Kustomization -images: -- name: controller - newName: quay.io/sustainable_computing_io/kepler-operator - newTag: "0.5.0" diff --git a/config/manifests/kustomization.yaml b/config/manifests/kustomization.yaml index 596609d1..ebd941b1 100644 --- a/config/manifests/kustomization.yaml +++ b/config/manifests/kustomization.yaml @@ -11,11 +11,11 @@ resources: # These patches remove the unnecessary "cert" volume and its manager container volumeMount. patchesJson6902: - target: - group: apps - version: v1 - kind: Deployment - name: controller-manager - namespace: system + group: apps + version: v1 + kind: Deployment + name: controller + namespace: system patch: |- # Remove the manager container's "cert" volumeMount, since OLM will create and mount a set of certs. # Update the indices in this path if adding or removing containers/volumeMounts in the manager's Deployment. diff --git a/config/prometheus/monitor.yaml b/config/prometheus/monitor.yaml index bdc624c5..56c1174f 100644 --- a/config/prometheus/monitor.yaml +++ b/config/prometheus/monitor.yaml @@ -1,4 +1,3 @@ - # Prometheus Monitor Service (Metrics) apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor @@ -19,3 +18,15 @@ spec: matchLabels: app.kubernetes.io/name: service app.kubernetes.io/part-of: kepler-operator + +# spec: +# endpoints: +# - path: /metrics +# port: https +# scheme: https +# bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token +# tlsConfig: +# insecureSkipVerify: true +# selector: +# matchLabels: +# control-plane: controller-manager diff --git a/config/rbac/auth_proxy_service.yaml b/config/rbac/auth_proxy_service.yaml index ab7f7dc1..2ac0e256 100644 --- a/config/rbac/auth_proxy_service.yaml +++ b/config/rbac/auth_proxy_service.yaml @@ -19,3 +19,12 @@ spec: selector: app.kubernetes.io/instance: controller-manager app.kubernetes.io/component: manager + +# spec: +# ports: +# - name: https +# port: 8443 +# protocol: TCP +# targetPort: https +# selector: +# control-plane: controller-manager diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index e5c2ee5b..68110066 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -64,6 +64,32 @@ rules: - '*' verbs: - '*' +- apiGroups: + - kepler.system.sustainable.computing.io + resources: + - keplers + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - kepler.system.sustainable.computing.io + resources: + - keplers/finalizers + verbs: + - update +- apiGroups: + - kepler.system.sustainable.computing.io + resources: + - keplers/status + verbs: + - get + - patch + - update - apiGroups: - monitoring.coreos.com resources: diff --git a/config/rbac/service_account.yaml b/config/rbac/service_account.yaml index 2a83c2ca..4a26793e 100644 --- a/config/rbac/service_account.yaml +++ b/config/rbac/service_account.yaml @@ -3,7 +3,7 @@ kind: ServiceAccount metadata: labels: app.kubernetes.io/name: serviceaccount - app.kubernetes.io/instance: controller-manager + app.kubernetes.io/instance: controller-manager-sa app.kubernetes.io/component: rbac app.kubernetes.io/created-by: kepler-operator app.kubernetes.io/part-of: kepler-operator diff --git a/config/scorecard/patches/basic.config.yaml b/config/scorecard/patches/basic.config.yaml index 35a0bc5a..893ebd2d 100644 --- a/config/scorecard/patches/basic.config.yaml +++ b/config/scorecard/patches/basic.config.yaml @@ -4,7 +4,7 @@ entrypoint: - scorecard-test - basic-check-spec - image: quay.io/operator-framework/scorecard-test:v1.25.1 + image: quay.io/operator-framework/scorecard-test:v1.35.0 labels: suite: basic test: basic-check-spec-test diff --git a/config/scorecard/patches/olm.config.yaml b/config/scorecard/patches/olm.config.yaml index b1161bd8..6cf777b8 100644 --- a/config/scorecard/patches/olm.config.yaml +++ b/config/scorecard/patches/olm.config.yaml @@ -4,7 +4,7 @@ entrypoint: - scorecard-test - olm-bundle-validation - image: quay.io/operator-framework/scorecard-test:v1.25.1 + image: quay.io/operator-framework/scorecard-test:v1.35.0 labels: suite: olm test: olm-bundle-validation-test @@ -14,7 +14,7 @@ entrypoint: - scorecard-test - olm-crds-have-validation - image: quay.io/operator-framework/scorecard-test:v1.25.1 + image: quay.io/operator-framework/scorecard-test:v1.35.0 labels: suite: olm test: olm-crds-have-validation-test @@ -24,7 +24,7 @@ entrypoint: - scorecard-test - olm-crds-have-resources - image: quay.io/operator-framework/scorecard-test:v1.25.1 + image: quay.io/operator-framework/scorecard-test:v1.35.0 labels: suite: olm test: olm-crds-have-resources-test @@ -34,7 +34,7 @@ entrypoint: - scorecard-test - olm-spec-descriptors - image: quay.io/operator-framework/scorecard-test:v1.25.1 + image: quay.io/operator-framework/scorecard-test:v1.35.0 labels: suite: olm test: olm-spec-descriptors-test @@ -44,7 +44,7 @@ entrypoint: - scorecard-test - olm-status-descriptors - image: quay.io/operator-framework/scorecard-test:v1.25.1 + image: quay.io/operator-framework/scorecard-test:v1.35.0 labels: suite: olm test: olm-status-descriptors-test diff --git a/config/webhook/kustomizeconfig.yaml b/config/webhook/kustomizeconfig.yaml index 25e21e3c..206316e5 100644 --- a/config/webhook/kustomizeconfig.yaml +++ b/config/webhook/kustomizeconfig.yaml @@ -1,4 +1,4 @@ -# the following config is for teaching kustomize where to look at when substituting vars. +# the following config is for teaching kustomize where to look at when substituting nameReference. # It requires kustomize v2.1.0 or newer to work properly. nameReference: - kind: Service @@ -20,6 +20,3 @@ namespace: group: admissionregistration.k8s.io path: webhooks/clientConfig/service/namespace create: true - -varReference: -- path: metadata/annotations diff --git a/config/webhook/service.yaml b/config/webhook/service.yaml index 65b196ae..69b283b1 100644 --- a/config/webhook/service.yaml +++ b/config/webhook/service.yaml @@ -19,3 +19,6 @@ spec: app.kubernetes.io/component: manager app.kubernetes.io/instance: controller-manager app.kubernetes.io/part-of: kepler-operator + + # selector: + # control-plane: controller-manager diff --git a/pkg/controllers/config.go b/controllers/config.go similarity index 100% rename from pkg/controllers/config.go rename to controllers/config.go diff --git a/pkg/controllers/kepler.go b/controllers/kepler.go similarity index 99% rename from pkg/controllers/kepler.go rename to controllers/kepler.go index ee2a46a2..55dc9109 100644 --- a/pkg/controllers/kepler.go +++ b/controllers/kepler.go @@ -9,7 +9,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" - "github.com/sustainable.computing.io/kepler-operator/pkg/api/v1alpha1" + "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" "github.com/sustainable.computing.io/kepler-operator/pkg/components" "github.com/sustainable.computing.io/kepler-operator/pkg/reconciler" "github.com/sustainable.computing.io/kepler-operator/pkg/utils/k8s" diff --git a/pkg/controllers/kepler_internal.go b/controllers/kepler_internal.go similarity index 99% rename from pkg/controllers/kepler_internal.go rename to controllers/kepler_internal.go index 75810858..893e362d 100644 --- a/pkg/controllers/kepler_internal.go +++ b/controllers/kepler_internal.go @@ -13,7 +13,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/predicate" "sigs.k8s.io/controller-runtime/pkg/reconcile" - "github.com/sustainable.computing.io/kepler-operator/pkg/api/v1alpha1" + "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" "github.com/sustainable.computing.io/kepler-operator/pkg/components" "github.com/sustainable.computing.io/kepler-operator/pkg/components/exporter" "github.com/sustainable.computing.io/kepler-operator/pkg/components/modelserver" diff --git a/pkg/controllers/reconcilers.go b/controllers/reconcilers.go similarity index 100% rename from pkg/controllers/reconcilers.go rename to controllers/reconcilers.go diff --git a/go.mod b/go.mod index 2fa85bb4..69956611 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,8 @@ toolchain go1.21.7 require ( github.com/cespare/xxhash/v2 v2.2.0 github.com/go-logr/logr v1.4.1 + github.com/onsi/ginkgo/v2 v2.14.0 + github.com/onsi/gomega v1.30.0 github.com/openshift/api v0.0.0-20240212125214-04ea3891d9cb github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.71.2 github.com/stretchr/testify v1.8.4 @@ -30,12 +32,14 @@ require ( github.com/go-openapi/jsonpointer v0.19.6 // indirect github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/swag v0.22.3 // indirect + github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/gnostic-models v0.6.8 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/gofuzz v1.2.0 // indirect + github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect github.com/google/uuid v1.3.0 // indirect github.com/imdario/mergo v0.3.6 // indirect github.com/josharian/intern v1.0.0 // indirect @@ -59,6 +63,7 @@ require ( golang.org/x/term v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.3.0 // indirect + golang.org/x/tools v0.17.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.33.0 // indirect diff --git a/go.sum b/go.sum index 92fb7184..73830301 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,9 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -49,6 +52,7 @@ github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJY github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28= github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= @@ -104,6 +108,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= @@ -138,6 +143,7 @@ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/hack/boilerplate.go.txt b/hack/boilerplate.go.txt index 6975adbe..ff72ff2a 100644 --- a/hack/boilerplate.go.txt +++ b/hack/boilerplate.go.txt @@ -1,5 +1,5 @@ /* -Copyright 2023. +Copyright 2024. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -12,4 +12,4 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -*/ +*/ \ No newline at end of file diff --git a/hack/bundle.sh b/hack/bundle.sh index 829ea390..41a7a3c1 100755 --- a/hack/bundle.sh +++ b/hack/bundle.sh @@ -58,7 +58,7 @@ main() { info "Found old version: $old_bundle_version" info "Building bundle version $VERSION" - run operator-sdk generate kustomize manifests --apis-dir=./pkg/api --verbose + run operator-sdk generate kustomize manifests --verbose local gen_opts=() read -r -a gen_opts <<<"$BUNDLE_GEN_FLAGS" diff --git a/hack/tools.sh b/hack/tools.sh index 5b5ccbc8..bfcaffd8 100755 --- a/hack/tools.sh +++ b/hack/tools.sh @@ -29,8 +29,8 @@ declare -r LOCAL_BIN="$PROJECT_ROOT/tmp/bin" # versions declare -r KUSTOMIZE_VERSION=${KUSTOMIZE_VERSION:-v3.8.7} -declare -r CONTROLLER_TOOLS_VERSION=${CONTROLLER_TOOLS_VERSION:-v0.12.1} -declare -r OPERATOR_SDK_VERSION=${OPERATOR_SDK_VERSION:-v1.27.0} +declare -r CONTROLLER_TOOLS_VERSION=${CONTROLLER_TOOLS_VERSION:-v0.13.0} +declare -r OPERATOR_SDK_VERSION=${OPERATOR_SDK_VERSION:-v1.35.0} declare -r YQ_VERSION=${YQ_VERSION:-v4.34.2} declare -r CRDOC_VERSION=${CRDOC_VERSION:-v0.6.2} declare -r OC_VERSION=${OC_VERSION:-4.13.0} diff --git a/internal/controller/kepler_controller.go b/internal/controller/kepler_controller.go new file mode 100644 index 00000000..4a7bf81a --- /dev/null +++ b/internal/controller/kepler_controller.go @@ -0,0 +1,62 @@ +/* +Copyright 2024. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package controller + +import ( + "context" + + "k8s.io/apimachinery/pkg/runtime" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" + + keplersystemv1alpha1 "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" +) + +// KeplerReconciler reconciles a Kepler object +type KeplerReconciler struct { + client.Client + Scheme *runtime.Scheme +} + +//+kubebuilder:rbac:groups=kepler.system.sustainable.computing.io,resources=keplers,verbs=get;list;watch;create;update;patch;delete +//+kubebuilder:rbac:groups=kepler.system.sustainable.computing.io,resources=keplers/status,verbs=get;update;patch +//+kubebuilder:rbac:groups=kepler.system.sustainable.computing.io,resources=keplers/finalizers,verbs=update + +// Reconcile is part of the main kubernetes reconciliation loop which aims to +// move the current state of the cluster closer to the desired state. +// TODO(user): Modify the Reconcile function to compare the state specified by +// the Kepler object against the actual cluster state, and then +// perform operations to make the cluster state reflect the state specified by +// the user. +// +// For more details, check Reconcile and its Result here: +// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.16.3/pkg/reconcile +func (r *KeplerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + _ = log.FromContext(ctx) + + // TODO(user): your logic here + + return ctrl.Result{}, nil +} + +// SetupWithManager sets up the controller with the Manager. +func (r *KeplerReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&keplersystemv1alpha1.Kepler{}). + Complete(r) +} diff --git a/internal/controller/kepler_controller_test.go b/internal/controller/kepler_controller_test.go new file mode 100644 index 00000000..40d3b7a6 --- /dev/null +++ b/internal/controller/kepler_controller_test.go @@ -0,0 +1,84 @@ +/* +Copyright 2024. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package controller + +import ( + "context" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + keplersystemv1alpha1 "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" +) + +var _ = Describe("Kepler Controller", func() { + Context("When reconciling a resource", func() { + const resourceName = "test-resource" + + ctx := context.Background() + + typeNamespacedName := types.NamespacedName{ + Name: resourceName, + Namespace: "default", // TODO(user):Modify as needed + } + kepler := &keplersystemv1alpha1.Kepler{} + + BeforeEach(func() { + By("creating the custom resource for the Kind Kepler") + err := k8sClient.Get(ctx, typeNamespacedName, kepler) + if err != nil && errors.IsNotFound(err) { + resource := &keplersystemv1alpha1.Kepler{ + ObjectMeta: metav1.ObjectMeta{ + Name: resourceName, + Namespace: "default", + }, + // TODO(user): Specify other spec details if needed. + } + Expect(k8sClient.Create(ctx, resource)).To(Succeed()) + } + }) + + AfterEach(func() { + // TODO(user): Cleanup logic after each test, like removing the resource instance. + resource := &keplersystemv1alpha1.Kepler{} + err := k8sClient.Get(ctx, typeNamespacedName, resource) + Expect(err).NotTo(HaveOccurred()) + + By("Cleanup the specific resource instance Kepler") + Expect(k8sClient.Delete(ctx, resource)).To(Succeed()) + }) + It("should successfully reconcile the resource", func() { + By("Reconciling the created resource") + controllerReconciler := &KeplerReconciler{ + Client: k8sClient, + Scheme: k8sClient.Scheme(), + } + + _, err := controllerReconciler.Reconcile(ctx, reconcile.Request{ + NamespacedName: typeNamespacedName, + }) + Expect(err).NotTo(HaveOccurred()) + // TODO(user): Add more specific assertions depending on your controller's reconciliation logic. + // Example: If you expect a certain status condition after reconciliation, verify it here. + }) + }) +}) diff --git a/internal/controller/suite_test.go b/internal/controller/suite_test.go new file mode 100644 index 00000000..6d09ba5d --- /dev/null +++ b/internal/controller/suite_test.go @@ -0,0 +1,90 @@ +/* +Copyright 2024. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package controller + +import ( + "fmt" + "path/filepath" + "runtime" + "testing" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/rest" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/envtest" + logf "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/log/zap" + + keplersystemv1alpha1 "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" + //+kubebuilder:scaffold:imports +) + +// These tests use Ginkgo (BDD-style Go testing framework). Refer to +// http://onsi.github.io/ginkgo/ to learn more about Ginkgo. + +var cfg *rest.Config +var k8sClient client.Client +var testEnv *envtest.Environment + +func TestControllers(t *testing.T) { + RegisterFailHandler(Fail) + + RunSpecs(t, "Controller Suite") +} + +var _ = BeforeSuite(func() { + logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) + + By("bootstrapping test environment") + testEnv = &envtest.Environment{ + CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")}, + ErrorIfCRDPathMissing: true, + + // The BinaryAssetsDirectory is only required if you want to run the tests directly + // without call the makefile target test. If not informed it will look for the + // default path defined in controller-runtime which is /usr/local/kubebuilder/. + // Note that you must have the required binaries setup under the bin directory to perform + // the tests directly. When we run make test it will be setup and used automatically. + BinaryAssetsDirectory: filepath.Join("..", "..", "bin", "k8s", + fmt.Sprintf("1.28.3-%s-%s", runtime.GOOS, runtime.GOARCH)), + } + + var err error + // cfg is defined in this file globally. + cfg, err = testEnv.Start() + Expect(err).NotTo(HaveOccurred()) + Expect(cfg).NotTo(BeNil()) + + err = keplersystemv1alpha1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + //+kubebuilder:scaffold:scheme + + k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) + Expect(err).NotTo(HaveOccurred()) + Expect(k8sClient).NotTo(BeNil()) + +}) + +var _ = AfterSuite(func() { + By("tearing down the test environment") + err := testEnv.Stop() + Expect(err).NotTo(HaveOccurred()) +}) diff --git a/pkg/components/estimator/estimator.go b/pkg/components/estimator/estimator.go index 737fd7de..a03e084b 100644 --- a/pkg/components/estimator/estimator.go +++ b/pkg/components/estimator/estimator.go @@ -20,7 +20,7 @@ import ( "fmt" "strings" - "github.com/sustainable.computing.io/kepler-operator/pkg/api/v1alpha1" + "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" "github.com/sustainable.computing.io/kepler-operator/pkg/utils/k8s" corev1 "k8s.io/api/core/v1" diff --git a/pkg/components/estimator/estimator_test.go b/pkg/components/estimator/estimator_test.go index bb95c3b0..0dbb1c7b 100644 --- a/pkg/components/estimator/estimator_test.go +++ b/pkg/components/estimator/estimator_test.go @@ -20,7 +20,7 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/sustainable.computing.io/kepler-operator/pkg/api/v1alpha1" + "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" "github.com/sustainable.computing.io/kepler-operator/pkg/utils/k8s" corev1 "k8s.io/api/core/v1" ) diff --git a/pkg/components/exporter/exporter.go b/pkg/components/exporter/exporter.go index 628cb219..df458987 100644 --- a/pkg/components/exporter/exporter.go +++ b/pkg/components/exporter/exporter.go @@ -22,7 +22,7 @@ import ( "regexp" "strconv" - "github.com/sustainable.computing.io/kepler-operator/pkg/api/v1alpha1" + "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" "github.com/sustainable.computing.io/kepler-operator/pkg/components" "github.com/sustainable.computing.io/kepler-operator/pkg/components/estimator" "github.com/sustainable.computing.io/kepler-operator/pkg/components/modelserver" diff --git a/pkg/components/exporter/exporter_test.go b/pkg/components/exporter/exporter_test.go index ed7fae2d..51427b60 100644 --- a/pkg/components/exporter/exporter_test.go +++ b/pkg/components/exporter/exporter_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/sustainable.computing.io/kepler-operator/pkg/api/v1alpha1" + "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" "github.com/sustainable.computing.io/kepler-operator/pkg/components" "github.com/sustainable.computing.io/kepler-operator/pkg/utils/k8s" corev1 "k8s.io/api/core/v1" diff --git a/pkg/components/modelserver/modelserver.go b/pkg/components/modelserver/modelserver.go index a8086fe2..07cecb5f 100644 --- a/pkg/components/modelserver/modelserver.go +++ b/pkg/components/modelserver/modelserver.go @@ -19,7 +19,7 @@ package modelserver import ( "fmt" - "github.com/sustainable.computing.io/kepler-operator/pkg/api/v1alpha1" + "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" "github.com/sustainable.computing.io/kepler-operator/pkg/components" "github.com/sustainable.computing.io/kepler-operator/pkg/utils/k8s" diff --git a/pkg/components/modelserver/modelserver_test.go b/pkg/components/modelserver/modelserver_test.go index b276a499..eb0b3993 100644 --- a/pkg/components/modelserver/modelserver_test.go +++ b/pkg/components/modelserver/modelserver_test.go @@ -20,7 +20,7 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/sustainable.computing.io/kepler-operator/pkg/api/v1alpha1" + "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" "github.com/sustainable.computing.io/kepler-operator/pkg/components" ) diff --git a/pkg/reconciler/kepler.go b/pkg/reconciler/kepler.go index 99430d72..7e012809 100644 --- a/pkg/reconciler/kepler.go +++ b/pkg/reconciler/kepler.go @@ -23,7 +23,7 @@ import ( "strconv" "github.com/cespare/xxhash/v2" - "github.com/sustainable.computing.io/kepler-operator/pkg/api/v1alpha1" + "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" "github.com/sustainable.computing.io/kepler-operator/pkg/components/exporter" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" diff --git a/pkg/utils/k8s/k8s.go b/pkg/utils/k8s/k8s.go index 96e7d5d1..e93fb85f 100644 --- a/pkg/utils/k8s/k8s.go +++ b/pkg/utils/k8s/k8s.go @@ -20,7 +20,7 @@ import ( "fmt" secv1 "github.com/openshift/api/security/v1" - "github.com/sustainable.computing.io/kepler-operator/pkg/api/v1alpha1" + "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/utils/pointer" diff --git a/pkg/utils/test/assertions.go b/pkg/utils/test/assertions.go index cabbd748..61604a8c 100644 --- a/pkg/utils/test/assertions.go +++ b/pkg/utils/test/assertions.go @@ -21,7 +21,7 @@ import ( "time" "github.com/stretchr/testify/assert" - "github.com/sustainable.computing.io/kepler-operator/pkg/api/v1alpha1" + "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" "github.com/sustainable.computing.io/kepler-operator/pkg/utils/k8s" "sigs.k8s.io/controller-runtime/pkg/client" diff --git a/pkg/utils/test/framework.go b/pkg/utils/test/framework.go index 6c5aa3cf..44918631 100644 --- a/pkg/utils/test/framework.go +++ b/pkg/utils/test/framework.go @@ -27,7 +27,7 @@ import ( "golang.org/x/exp/slices" "github.com/stretchr/testify/assert" - "github.com/sustainable.computing.io/kepler-operator/pkg/api/v1alpha1" + "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" "github.com/sustainable.computing.io/kepler-operator/pkg/utils/k8s" "github.com/sustainable.computing.io/kepler-operator/pkg/utils/test/oc" ctrl "sigs.k8s.io/controller-runtime" diff --git a/pkg/utils/test/kepler_internal_builder.go b/pkg/utils/test/kepler_internal_builder.go index c1883568..6c72ffbf 100644 --- a/pkg/utils/test/kepler_internal_builder.go +++ b/pkg/utils/test/kepler_internal_builder.go @@ -17,7 +17,7 @@ limitations under the License. package test import ( - "github.com/sustainable.computing.io/kepler-operator/pkg/api/v1alpha1" + "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" "github.com/sustainable.computing.io/kepler-operator/pkg/utils/k8s" ) diff --git a/tests/Dockerfile b/tests/Dockerfile index d4de77b5..cda01ede 100644 --- a/tests/Dockerfile +++ b/tests/Dockerfile @@ -11,12 +11,14 @@ RUN go mod download # Install kubectl and oc RUN curl -L -o oc.tar.gz https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/latest/openshift-client-linux.tar.gz \ - && tar -xvzf oc.tar.gz \ - && chmod +x kubectl oc \ - && mv oc kubectl /usr/local/bin/ + && tar -xvzf oc.tar.gz \ + && chmod +x kubectl oc \ + && mv oc kubectl /usr/local/bin/ # Copy the go source COPY pkg/ pkg/ +COPY api/ api/ +COPY controllers/ controllers/ COPY tests/ tests/ # Compile test into e2e.test binary diff --git a/tests/e2e/kepler_internal_test.go b/tests/e2e/kepler_internal_test.go index 5dbc344e..320146af 100644 --- a/tests/e2e/kepler_internal_test.go +++ b/tests/e2e/kepler_internal_test.go @@ -22,9 +22,9 @@ import ( "time" "github.com/stretchr/testify/assert" - "github.com/sustainable.computing.io/kepler-operator/pkg/api/v1alpha1" + "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" + "github.com/sustainable.computing.io/kepler-operator/controllers" "github.com/sustainable.computing.io/kepler-operator/pkg/components/exporter" - "github.com/sustainable.computing.io/kepler-operator/pkg/controllers" "github.com/sustainable.computing.io/kepler-operator/pkg/utils/k8s" "github.com/sustainable.computing.io/kepler-operator/pkg/utils/test" appsv1 "k8s.io/api/apps/v1" diff --git a/tests/e2e/kepler_test.go b/tests/e2e/kepler_test.go index 168647cc..c7e553b3 100644 --- a/tests/e2e/kepler_test.go +++ b/tests/e2e/kepler_test.go @@ -6,9 +6,9 @@ import ( "github.com/stretchr/testify/assert" - "github.com/sustainable.computing.io/kepler-operator/pkg/api/v1alpha1" + "github.com/sustainable.computing.io/kepler-operator/api/v1alpha1" + "github.com/sustainable.computing.io/kepler-operator/controllers" "github.com/sustainable.computing.io/kepler-operator/pkg/components" - "github.com/sustainable.computing.io/kepler-operator/pkg/controllers" "github.com/sustainable.computing.io/kepler-operator/pkg/utils/k8s" "github.com/sustainable.computing.io/kepler-operator/pkg/utils/test" appsv1 "k8s.io/api/apps/v1" diff --git a/tests/e2e/main_test.go b/tests/e2e/main_test.go index 1ace9490..dc129edb 100644 --- a/tests/e2e/main_test.go +++ b/tests/e2e/main_test.go @@ -21,7 +21,7 @@ import ( "os" "testing" - "github.com/sustainable.computing.io/kepler-operator/pkg/controllers" + "github.com/sustainable.computing.io/kepler-operator/controllers" "github.com/sustainable.computing.io/kepler-operator/pkg/utils/k8s" )