Skip to content

Commit

Permalink
feat: migrate operator code base to support new operator-sdk version
Browse files Browse the repository at this point in the history
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 <vibhu.sharma2929@gmail.com>
  • Loading branch information
vprashar2929 committed Jun 26, 2024
1 parent 7d7d3a0 commit b15cc21
Show file tree
Hide file tree
Showing 62 changed files with 540 additions and 159 deletions.
22 changes: 13 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.21 as builder
FROM golang:1.21 AS builder
ARG TARGETOS
ARG TARGETARCH

Expand All @@ -12,28 +12,32 @@ 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
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# 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/
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) \
Expand Down
7 changes: 6 additions & 1 deletion PROJECT
Original file line number Diff line number Diff line change
@@ -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: {}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions bundle.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 29 additions & 7 deletions bundle/manifests/kepler-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions bundle/metadata/annotations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions bundle/tests/scorecard/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmd/manager/main.go → cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
10 changes: 5 additions & 5 deletions config/certmanager/certificate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 1 addition & 9 deletions config/certmanager/kustomizeconfig.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
# 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
fieldSpecs:
- 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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion config/crd/patches/cainjection_in_keplers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit b15cc21

Please sign in to comment.