Skip to content

Commit 5727db9

Browse files
operator-sdk upgrade to 1.4.2
Upgrade the operator-framework version we use for the NFD-Operator, currently uses a very old and deprecated one. this patchs bumps it to 1.4.2 version, adding kustomize as the way to handle the manifests as part of the new features of the framwork Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
1 parent ab1b7d4 commit 5727db9

File tree

77 files changed

+2536
-1039
lines changed

Some content is hidden

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

77 files changed

+2536
-1039
lines changed

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore all files which are not go type
3+
!**/*.go
4+
!**/*.mod
5+
!**/*.sum

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
# Binaries for programs and plugins
3+
*.exe
4+
*.exe~
5+
*.dll
6+
*.so
7+
*.dylib
8+
bin
9+
testbin/*
10+
11+
# Test binary, build with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Kubernetes Generated files - skip generated files, except for vendored files
18+
19+
!vendor/**/zz_generated.*
20+
21+
# editor and IDE paraphernalia
22+
.idea
23+
*.swp
24+
*.swo
25+
*~

Dockerfile

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1-
# Build the operator
2-
FROM golang:1.15.4 AS builder
3-
WORKDIR /go/src/github.com/kubernetes-sigs/node-feature-discovery-operator
1+
# Build the manager binary
2+
FROM golang:1.15.4 as builder
43

5-
# Fetch/cache dependencies
4+
WORKDIR /workspace
5+
# Copy the Go Modules manifests
66
COPY go.mod go.sum ./
7+
8+
# cache deps before building and copying source so that we don't need to re-download as much
9+
# and so that source changes don't invalidate our downloaded layer
710
RUN go mod download
811

9-
# do the actual build
12+
# Build
1013
COPY . .
1114
RUN make build
1215

1316
# Create production image for running the operator
1417
FROM registry.access.redhat.com/ubi8/ubi
15-
COPY --from=builder /go/src/github.com/kubernetes-sigs/node-feature-discovery-operator/node-feature-discovery-operator /usr/bin/
18+
COPY --from=builder /workspace/node-feature-discovery-operator /
1619

1720
RUN mkdir -p /opt/nfd
18-
COPY assets /opt/nfd
21+
COPY build/assets /opt/nfd
22+
23+
RUN useradd nfd-operator
24+
USER nfd-operator
1925

20-
RUN useradd node-feature-discovery-operator
21-
USER node-feature-discovery-operator
22-
ENTRYPOINT ["/usr/bin/node-feature-discovery-operator"]
26+
ENTRYPOINT ["/node-feature-discovery-operator"]
2327
LABEL io.k8s.display-name="node-feature-discovery-operator"

Makefile

Lines changed: 127 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,40 @@ SITE_BASEURL ?=
2020
SITE_DESTDIR ?= _site
2121
JEKYLL_OPTS := -d '$(SITE_DESTDIR)' $(if $(SITE_BASEURL),-b '$(SITE_BASEURL)',)
2222

23+
# VERSION defines the project version for the bundle.
24+
# Update this value when you upgrade the version of your project.
25+
# To re-generate a bundle for another specific version without changing the standard setup, you can:
26+
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.2.1)
27+
# - use environment variables to overwrite this value (e.g export VERSION=0.2.1)
2328
VERSION := $(shell git describe --tags --dirty --always)
2429

30+
# CHANNELS define the bundle channels used in the bundle.
31+
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "preview,fast,stable")
32+
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
33+
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=preview,fast,stable)
34+
# - use environment variables to overwrite this value (e.g export CHANNELS="preview,fast,stable")
35+
ifneq ($(origin CHANNELS), undefined)
36+
BUNDLE_CHANNELS := --channels=$(CHANNELS)
37+
endif
38+
39+
# DEFAULT_CHANNEL defines the default channel used in the bundle.
40+
# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
41+
# To re-generate a bundle for any other default channel without changing the default setup, you can:
42+
# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
43+
# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
44+
ifneq ($(origin DEFAULT_CHANNEL), undefined)
45+
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
46+
endif
47+
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
48+
49+
# BUNDLE_IMG defines the image:tag used for the bundle.
50+
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
51+
BUNDLE_IMG ?= controller-bundle:$(VERSION)
52+
53+
# Image URL to use all building/pushing image targets
54+
IMAGE_BUILD_CMD ?= docker build
55+
IMAGE_PUSH_CMD ?= docker push
56+
IMAGE_BUILD_EXTRA_OPTS ?=
2557
IMAGE_REGISTRY ?= k8s.gcr.io/nfd
2658
IMAGE_NAME := node-feature-discovery-operator
2759
IMAGE_TAG_NAME ?= $(VERSION)
@@ -30,54 +62,69 @@ IMAGE_REPO := $(IMAGE_REGISTRY)/$(IMAGE_NAME)
3062
IMAGE_TAG := $(IMAGE_REPO):$(IMAGE_TAG_NAME)
3163
IMAGE_EXTRA_TAGS := $(foreach tag,$(IMAGE_EXTRA_TAG_NAMES),$(IMAGE_REPO):$(tag))
3264

33-
NAMESPACE := node-feature-discovery-operator
34-
PULLPOLICY ?= Always
35-
TEMPLATE_CMD = sed 's+REPLACE_IMAGE+$(IMAGE_TAG)+g; s+REPLACE_NAMESPACE+$(NAMESPACE)+g; s+IfNotPresent+$(PULLPOLICY)+'
36-
GOFMT_CHECK=$(shell find . -not \( \( -wholename './.*' -o -wholename '*/vendor/*' \) -prune \) -name '*.go' | sort -u | xargs gofmt -s -l)
65+
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
66+
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
3767

38-
DEPLOY_OBJECTS = manifests/0100_namespace.yaml manifests/0200_service_account.yaml manifests/0300_cluster_role.yaml manifests/0400_cluster_role_binding.yaml manifests/0600_operator.yaml
39-
DEPLOY_CRDS = manifests/0500_crd.yaml
40-
DEPLOY_CRS = manifests/0700_cr.yaml
68+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
69+
ifeq (,$(shell go env GOBIN))
70+
GOBIN=$(shell go env GOPATH)/bin
71+
else
72+
GOBIN=$(shell go env GOBIN)
73+
endif
4174

42-
PACKAGE=github.com/kubernetes-sigs/node-feature-discovery-operator
43-
MAIN_PACKAGE=$(PACKAGE)/cmd/manager
75+
GOOS=linux
4476

77+
PACKAGE=github.com/kubernetes-sigs/node-feature-discovery-operator
78+
MAIN_PACKAGE=main.go
4579
BIN=node-feature-discovery-operator
4680

47-
DOCKERFILE=Dockerfile
48-
49-
GOOS=linux
50-
5181
all: build
5282

83+
# Run tests
84+
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
85+
test: generate fmt vet manifests
86+
mkdir -p ${ENVTEST_ASSETS_DIR}
87+
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.0/hack/setup-envtest.sh
88+
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
5389
go_mod:
5490
@go mod download
5591

92+
# Build binary
5693
build: go_mod
57-
@GOOS=$(GOOS) go build -o $(BIN) $(MAIN_PACKAGE)
58-
59-
deploy-crds:
60-
for obj in $(DEPLOY_CRDS); do \
61-
$(TEMPLATE_CMD) $$obj | kubectl apply -f - ;\
62-
sleep 1;\
63-
done
64-
65-
deploy-objects: deploy-crds
66-
for obj in $(DEPLOY_OBJECTS); do \
67-
$(TEMPLATE_CMD) $$obj | kubectl apply -f - ;\
68-
sleep 1;\
69-
done
70-
71-
deploy: deploy-objects
72-
for obj in $(DEPLOY_CRS); do \
73-
$(TEMPLATE_CMD) $$obj | kubectl apply -f - ;\
74-
sleep 1;\
75-
done
94+
@GOOS=$(GOOS) GO111MODULE=on CGO_ENABLED=0 go build -o $(BIN) $(MAIN_PACKAGE)
7695

96+
# Run against the configured Kubernetes cluster in ~/.kube/config
97+
run: generate fmt vet manifests
98+
go run ./main.go
99+
100+
# Install CRDs into a cluster
101+
install: manifests kustomize
102+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
103+
104+
# Uninstall CRDs from a cluster
105+
uninstall: manifests kustomize
106+
$(KUSTOMIZE) build config/crd | kubectl delete -f -
107+
108+
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
109+
deploy: kustomize
110+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMAGE_TAG}
111+
$(KUSTOMIZE) build config/default | kubectl apply -f -
112+
113+
# UnDeploy controller from the configured Kubernetes cluster in ~/.kube/config
77114
undeploy:
78-
for obj in $(DEPLOY_OBJECTS) $(DEPLOY_CRDS) $(DEPLOY_CRS); do \
79-
$(TEMPLATE_CMD) $$obj | kubectl delete -f - ;\
80-
done
115+
$(KUSTOMIZE) build config/default | kubectl delete -f -
116+
117+
# Generate manifests e.g. CRD, RBAC etc.
118+
manifests: controller-gen
119+
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
120+
121+
# Run go fmt against code
122+
fmt:
123+
go fmt ./...
124+
125+
# Run go vet against code
126+
vet:
127+
go vet ./...
81128

82129
verify: verify-gofmt ci-lint
83130

@@ -94,17 +141,22 @@ clean:
94141
go clean
95142
rm -f $(BIN)
96143

144+
# clean NFD labels on all nodes
145+
# devel only
97146
clean-labels:
98147
kubectl get no -o yaml | sed -e '/^\s*nfd.node.kubernetes.io/d' -e '/^\s*feature.node.kubernetes.io/d' | kubectl replace -f -
99148

100-
image:
149+
# Generate code
150+
generate: controller-gen
151+
$(CONTROLLER_GEN) object:headerFile="utils/boilerplate.go.txt" paths="./..."
152+
153+
# Build the docker image
154+
image:
101155
$(IMAGE_BUILD_CMD) -t $(IMAGE_TAG) \
102156
$(foreach tag,$(IMAGE_EXTRA_TAGS),-t $(tag)) \
103157
$(IMAGE_BUILD_EXTRA_OPTS) ./
104158

105-
test:
106-
go test ./cmd/... ./pkg/... -coverprofile cover.out
107-
159+
# Push the docker image
108160
push:
109161
$(IMAGE_PUSH_CMD) $(IMAGE_TAG)
110162
for tag in $(IMAGE_EXTRA_TAGS); do $(IMAGE_PUSH_CMD) $$tag; done
@@ -119,3 +171,39 @@ site-serve:
119171

120172
.PHONY: all build test generate verify verify-gofmt clean deploy-objects deploy-operator deploy-crds push image
121173
.SILENT: go_mod
174+
# Download controller-gen locally if necessary
175+
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
176+
controller-gen:
177+
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
178+
179+
# Download kustomize locally if necessary
180+
KUSTOMIZE = $(shell pwd)/bin/kustomize
181+
kustomize:
182+
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
183+
184+
# go-get-tool will 'go get' any package $2 and install it to $1.
185+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
186+
define go-get-tool
187+
@[ -f $(1) ] || { \
188+
set -e ;\
189+
TMP_DIR=$$(mktemp -d) ;\
190+
cd $$TMP_DIR ;\
191+
go mod init tmp ;\
192+
echo "Downloading $(2)" ;\
193+
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
194+
rm -rf $$TMP_DIR ;\
195+
}
196+
endef
197+
198+
# Generate bundle manifests and metadata, then validate generated files.
199+
.PHONY: bundle
200+
bundle: manifests kustomize
201+
operator-sdk generate kustomize manifests -q
202+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMAGE_TAG)
203+
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
204+
operator-sdk bundle validate ./bundle
205+
206+
# Build the bundle image.
207+
.PHONY: bundle-build
208+
bundle-build:
209+
$(IMAGE_BUILD_CMD) -f bundle.Dockerfile -t $(BUNDLE_IMG) .

PROJECT

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
domain: nodefeaturediscoveries.nfd.kubernetes.io
2+
layout: go.kubebuilder.io/v3
3+
projectName: node-feature-discovery-operator
4+
repo: github.com/kubernetes-sigs/node-feature-discovery-operator
5+
resources:
6+
- crdVersion: v1
7+
group: nfd.kubernetes.io
8+
kind: NodeFeatureDiscovery
9+
version: v1
10+
version: 3-alpha
11+
plugins:
12+
manifests.sdk.operatorframework.io/v2: {}
13+
scorecard.sdk.operatorframework.io/v2: {}

api/v1/groupversion_info.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2021. The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1 contains API Schema definitions for the nfd.kubernetes.io v1 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=nfd.kubernetes.io
20+
package v1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "nfd.kubernetes.io", Version: "v1"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

pkg/apis/nfd/v1/nodefeaturediscovery_types.go renamed to api/v1/nodefeaturediscovery_types.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1+
/*
2+
Copyright 2021. The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package v1
218

319
import (
20+
conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"
421
corev1 "k8s.io/api/core/v1"
522
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
623
)
@@ -33,14 +50,17 @@ type ConfigSpec struct {
3350

3451
// NodeFeatureDiscoveryStatus defines the observed state of NodeFeatureDiscovery
3552
// +k8s:openapi-gen=true
36-
type NodeFeatureDiscoveryStatus struct{}
37-
38-
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
53+
type NodeFeatureDiscoveryStatus struct {
54+
// Conditions represents the latest available observations of current state.
55+
// +optional
56+
Conditions []conditionsv1.Condition `json:"conditions,omitempty"`
57+
}
3958

40-
// NodeFeatureDiscovery is the Schema for the nodefeaturediscoveries API
41-
// +k8s:openapi-gen=true
59+
// +kubebuilder:object:root=true
4260
// +kubebuilder:subresource:status
4361
// +kubebuilder:resource:path=nodefeaturediscoveries,scope=Namespaced
62+
63+
// NodeFeatureDiscovery is the Schema for the nodefeaturediscoveries API
4464
type NodeFeatureDiscovery struct {
4565
metav1.TypeMeta `json:",inline"`
4666
metav1.ObjectMeta `json:"metadata,omitempty"`
@@ -49,6 +69,7 @@ type NodeFeatureDiscovery struct {
4969
Status NodeFeatureDiscoveryStatus `json:"status,omitempty"`
5070
}
5171

72+
// +kubebuilder:object:root=true
5273
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
5374

5475
// NodeFeatureDiscoveryList contains a list of NodeFeatureDiscovery

0 commit comments

Comments
 (0)