Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate operator code base to support new operator-sdk version #404

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 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 @@ -11,29 +11,32 @@ COPY go.sum go.sum
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
# Copy must-gather scripts
COPY must-gather/ must-gather/
COPY cmd/ cmd/
COPY pkg/ pkg/

# Copy the go source
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY pkg/ pkg/
COPY internal/ internal/

# 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
6 changes: 5 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 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
8 changes: 2 additions & 6 deletions bundle/manifests/kepler-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ metadata:
containerImage: quay.io/sustainable_computing_io/kepler-operator:0.13.0
createdAt: "2024-07-11T07:04:57Z"
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 @@ -302,10 +302,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
20 changes: 10 additions & 10 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/internal/controller"
"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 Expand Up @@ -87,7 +87,7 @@ func main() {
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")

flag.StringVar(&controllers.KeplerDeploymentNS, "deployment-namespace", controllers.KeplerDeploymentNS,
flag.StringVar(&controller.KeplerDeploymentNS, "deployment-namespace", controller.KeplerDeploymentNS,
"Namespace where kepler and its components are deployed.")

flag.CommandLine.Var(flag.Value(&additionalNamespaces), "watch-namespaces",
Expand All @@ -98,10 +98,10 @@ func main() {

// NOTE: RELATED_IMAGE_KEPLER can be set as env or flag, flag takes precedence over env
keplerImage := os.Getenv("RELATED_IMAGE_KEPLER")
flag.StringVar(&controllers.Config.Image, "kepler.image", keplerImage, "kepler image")
flag.StringVar(&controller.Config.Image, "kepler.image", keplerImage, "kepler image")

flag.StringVar(&controllers.InternalConfig.ModelServerImage, "estimator.image", estimator.StableImage, "kepler estimator image")
flag.StringVar(&controllers.InternalConfig.EstimatorImage, "model-server.image", modelserver.StableImage, "kepler model server image")
flag.StringVar(&controller.InternalConfig.ModelServerImage, "estimator.image", estimator.StableImage, "kepler estimator image")
flag.StringVar(&controller.InternalConfig.EstimatorImage, "model-server.image", modelserver.StableImage, "kepler model server image")

opts := zap.Options{
Development: true,
Expand All @@ -112,7 +112,7 @@ func main() {
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

if openshift {
controllers.Config.Cluster = k8s.OpenShift
controller.Config.Cluster = k8s.OpenShift
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Expand All @@ -123,7 +123,7 @@ func main() {
// TODO: add new introduced namespace from KeplerInternal.Spec.Deployment.Namespace
NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
cacheNs := map[string]cache.Config{
controllers.KeplerDeploymentNS: {},
controller.KeplerDeploymentNS: {},
}
if openshift {
cacheNs[exporter.DashboardNs] = cache.Config{}
Expand Down Expand Up @@ -156,14 +156,14 @@ func main() {
os.Exit(1)
}

if err = (&controllers.KeplerReconciler{
if err = (&controller.KeplerReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "kepler")
os.Exit(1)
}
if err = (&controllers.KeplerInternalReconciler{
if err = (&controller.KeplerInternalReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
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
Loading
Loading