Skip to content

Commit

Permalink
bump kb with the latest changes/fixes (operator-framework#5330)
Browse files Browse the repository at this point in the history
* bump kb with the latest changes/fixes  - v3.2.0
  • Loading branch information
camilamacedo86 authored Nov 18, 2021
1 parent f6326e8 commit 67ac820
Show file tree
Hide file tree
Showing 28 changed files with 223 additions and 57 deletions.
78 changes: 78 additions & 0 deletions changelog/fragments/bump_kb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# entries is a list of entries to include in
# release notes and/or the migration guide
entries:
- description: >
For a more consistent user experience, ensure that all areas that require to be changed are marked by `TODO(user)`.
kind: "change"
breaking: false
- description: >
Add annotation to specify the default container. More info [here](https://kubernetes.io/docs/reference/labels-annotations-taints/#kubectl-kubernetes-io-default-container)
kind: "addition"
breaking: false
migration:
header: Add annotation to specify the default container
body: >
Add the following annotation into the file `config/manager/manager.yaml`
```yaml
...
template:
metadata:
annotations:
kubectl.kubernetes.io/default-container: manager
...
```
- description: >
Add PHONY targets to Makefile
kind: "addition"
breaking: false
migration:
header: Add PHONY targets to Makefile
body: >
Add PHONY target to all Makefile targets. For example, refer to the `Makefile` in `operator-sdk/testdata` directory of [OperatorSDK](https://github.com/operator-framework/operator-sdk) tagged by the release containing this change.
- description: >
Add `# TODO(user): Configure the resources accordingly based on the project requirements.` into the
file `config/manager/manager.yaml` to make this requirement clear for users. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
kind: "addition"
breaking: false
- description: >
For Helm-based Operators, adopted the same default resource limit values used to scaffold Golang-based projects.
kind: "change"
breaking: false
- description: >
For Golang-based Operators, increase the values used in the default scaffold to define the resource limits usage
and make clear the need to optimize its values based on the Operator requirements.
kind: "change"
breaking: false
- description: >
Improve scaffolding to filter existing multiline code fragments. More info [kubernetes-sigs/kubebuilder#2343](https://github.com/kubernetes-sigs/kubebuilder/pull/2343/files)
kind: "bugfix"
breaking: false
- description: >
For Golang-based projects, added `ignore-not-found` flag to the `uninstall` and `undeploy` Makefile targets.
This change allows `make undeploy` and `make install` to continue if Kustomize encounters a missing resource.
You can invoke this feature by calling `make undeploy ignore-not-found=true`
kind: "addition"
breaking: false
migration:
header: For Golang-based projects, add the flag `ignore-not-found` into the Makefile for the `uninstall` and `undeploy` targets
body: >
Update the Makefile with the following changes.
1) Above `##@ Deployment` add the following:
```
...
ifndef ignore-not-found
ignore-not-found = false
endif
...
```
2) Replace:
```sh
kubectl delete -f -
```
With:
```sh
kubectl delete --ignore-not-found=$(ignore-not-found) -f -
```
**NOTE** You can also compare your `Makefile` with the one tagged by this release, in `operator-sdk/testdata` of the [OperatorSDK](https://github.com/operator-framework/operator-sdk) project.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ require (
k8s.io/kubectl v0.21.0
sigs.k8s.io/controller-runtime v0.10.0
sigs.k8s.io/controller-tools v0.7.0
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20211001202619-87eb9d55ecdc
sigs.k8s.io/kubebuilder/v3 v3.2.0
sigs.k8s.io/yaml v1.2.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1870,8 +1870,8 @@ sigs.k8s.io/controller-tools v0.7.0 h1:iZIz1vEcavyEfxjcTLs1WH/MPf4vhPCtTKhoHqV8/
sigs.k8s.io/controller-tools v0.7.0/go.mod h1:bpBAo0VcSDDLuWt47evLhMLPxRPxMDInTEH/YbdeMK0=
sigs.k8s.io/kind v0.10.0/go.mod h1:fb32zUw7ewC47bPwLnwhf47wd/vADtv3c38KP7sjIlo=
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20210702145813-742983631190/go.mod h1:pUhjQx9f/+cn1OtSa5zMohY1lgk9s/9Mbcvwj82lrNk=
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20211001202619-87eb9d55ecdc h1:7HqFWk9fT5OfkZvY2CVHVrkRZAgS7n9rqsISG64/958=
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20211001202619-87eb9d55ecdc/go.mod h1:I7A2uB9NFAENStOGkI96dvx9D0uPH2uAiwjSQcyFSkU=
sigs.k8s.io/kubebuilder/v3 v3.2.0 h1:ttmajmBGZnqzV7RZd3zGGfj6dqJwGIzIdKsUX3cvYU8=
sigs.k8s.io/kubebuilder/v3 v3.2.0/go.mod h1:I7A2uB9NFAENStOGkI96dvx9D0uPH2uAiwjSQcyFSkU=
sigs.k8s.io/kustomize v2.0.3+incompatible h1:JUufWFNlI44MdtnjUqVnvh29rR37PQFzPbLXqhyOyX0=
sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU=
sigs.k8s.io/kustomize/api v0.8.5 h1:bfCXGXDAbFbb/Jv5AhMj2BB8a5VAJuuQ5/KU69WtDjQ=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (ma *AdvancedMolecule) Run() {
log.Infof("updating spec of inventorytest sample")
err = kbutil.ReplaceInFile(
filepath.Join(ma.ctx.Dir, "config", "samples", "test_v1alpha1_inventorytest.yaml"),
"# Add fields here",
"# TODO(user): Add fields here",
"size: 3")
pkg.CheckError("updating spec of inventorytest sample", err)

Expand Down
2 changes: 1 addition & 1 deletion hack/generate/samples/internal/ansible/memcached.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@ func (ma *Memcached) addingAnsibleTask() {

err = kbutil.ReplaceInFile(filepath.Join(ma.ctx.Dir, "config", "samples",
fmt.Sprintf("%s_%s_%s.yaml", ma.ctx.Group, ma.ctx.Version, strings.ToLower(ma.ctx.Kind))),
"# Add fields here", "size: 1")
"# TODO(user): Add fields here", "size: 1")
pkg.CheckError("updating sample CR", err)
}
6 changes: 3 additions & 3 deletions hack/generate/samples/internal/ansible/memcached_molecule.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (ma *MemcachedMolecule) Run() {
log.Infof("updating spec of foo sample")
err = kbutil.ReplaceInFile(
filepath.Join(ma.ctx.Dir, "config", "samples", "cache_v1alpha1_foo.yaml"),
"# Add fields here",
"# TODO(user): Add fields here",
"foo: bar")
pkg.CheckError("updating spec of cache_v1alpha1_foo.yaml", err)

Expand All @@ -124,7 +124,7 @@ func (ma *MemcachedMolecule) Run() {
log.Infof("updating spec of Memfin sample")
err = kbutil.ReplaceInFile(
filepath.Join(ma.ctx.Dir, "config", "samples", "cache_v1alpha1_memfin.yaml"),
"# Add fields here",
"# TODO(user): Add fields here",
"foo: bar")
pkg.CheckError("updating spec of cache_v1alpha1_memfin.yaml ", err)

Expand Down Expand Up @@ -158,7 +158,7 @@ func (ma *MemcachedMolecule) Run() {
log.Infof("updating spec of ignore sample")
err = kbutil.ReplaceInFile(
filepath.Join(ma.ctx.Dir, "config", "samples", "ignore_v1_secret.yaml"),
"# Add fields here",
"# TODO(user): Add fields here",
"foo: bar")
pkg.CheckError("updating spec of ignore_v1_secret.yaml", err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (mh *Memcached) implementingController() {

// Add reconcile implementation
err = kbtutil.ReplaceInFile(controllerPath,
"// your logic here", reconcileFragment)
"// TODO(user): your logic here", reconcileFragment)
pkg.CheckError("replacing reconcile", err)

// Add helpers funcs to the controller
Expand Down Expand Up @@ -292,7 +292,7 @@ func (mh *Memcached) implementingAPI() {
fmt.Sprintf("%s_%s_%s.yaml", mh.ctx.Group, mh.ctx.Version, strings.ToLower(mh.ctx.Kind)))

log.Infof("updating sample to have size attribute")
err = kbtutil.ReplaceInFile(filepath.Join(mh.ctx.Dir, sampleFile), "# Add fields here", "size: 1")
err = kbtutil.ReplaceInFile(filepath.Join(mh.ctx.Dir, sampleFile), "# TODO(user): Add fields here", "size: 1")
pkg.CheckError("updating sample", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (mh *Memcached) implementingController() {

// Add reconcile implementation
err = kbutil.ReplaceInFile(controllerPath,
"// your logic here", reconcileFragment)
"// TODO(user): your logic here", reconcileFragment)
pkg.CheckError("replacing reconcile content", err)

// Add helpers funcs to the controller
Expand Down Expand Up @@ -293,7 +293,7 @@ func (mh *Memcached) implementingAPI() {
fmt.Sprintf("%s_%s_%s.yaml", mh.ctx.Group, mh.ctx.Version, strings.ToLower(mh.ctx.Kind)))

log.Infof("updating sample to have size attribute")
err = kbutil.ReplaceInFile(filepath.Join(mh.ctx.Dir, sampleFile), "# Add fields here", "size: 1")
err = kbutil.ReplaceInFile(filepath.Join(mh.ctx.Dir, sampleFile), "# TODO(user): Add fields here", "size: 1")
pkg.CheckError("updating sample", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ kind: Memcached
metadata:
name: memcached-sample
spec:
# Add fields here
# TODO(user): Add fields here
foo: bar
---
apiVersion: admissionregistration.k8s.io/v1
Expand Down
8 changes: 4 additions & 4 deletions internal/plugins/ansible/v1/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ func addInitCustomizations(projectName string) error {
// todo: remove it when we solve the issue operator-framework/operator-sdk#3573
const resourcesLimitsFragment = ` resources:
limits:
cpu: 200m
memory: 100Mi
cpu: 500m
memory: 128Mi
requests:
cpu: 100m
memory: 20Mi
cpu: 10m
memory: 64Mi
`
err = util.ReplaceInFile(managerFile, resourcesLimitsFragment, "")
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const makefileTemplate = `
# Image URL to use all building/pushing image targets
IMG ?= {{ .Image }}
.PHONY: all
all: docker-build
##@ General
Expand All @@ -83,32 +84,40 @@ all: docker-build
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Build
.PHONY: run
run: ansible-operator ## Run against the configured Kubernetes cluster in ~/.kube/config
ANSIBLE_ROLES_PATH="$(ANSIBLE_ROLES_PATH):$(shell pwd)/roles" $(ANSIBLE_OPERATOR) run
.PHONY: docker-build
docker-build: ## Build docker image with the manager.
docker build -t ${IMG} .
.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${IMG}
##@ Deployment
.PHONY: install
install: kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
.PHONY: uninstall
uninstall: kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl delete -f -
.PHONY: deploy
deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl delete -f -
Expand Down
6 changes: 0 additions & 6 deletions internal/plugins/helm/v1/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,6 @@ func addInitCustomizations(projectName string) error {
return err
}

// Increase the default memory required.
err = util.ReplaceInFile(managerFile, "memory: 20Mi", "memory: 60Mi")
if err != nil {
return err
}

// Remove the webhook option for the componentConfig since webhooks are not supported by helm
err = util.ReplaceInFile(filepath.Join("config", "manager", "controller_manager_config.yaml"),
"webhook:\n port: 9443", "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (f *CustomResource) GetFuncMap() template.FuncMap {
return fm
}

const defaultSpecTemplate = `# Add fields here
const defaultSpecTemplate = `# TODO(user): Add fields here
`

const customResourceTemplate = `apiVersion: {{ .Resource.QualifiedGroup }}/{{ .Resource.Version }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const makefileTemplate = `
# Image URL to use all building/pushing image targets
IMG ?= {{ .Image }}
.PHONY: all
all: docker-build
##@ General
Expand All @@ -83,32 +84,40 @@ all: docker-build
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Build
.PHONY: run
run: helm-operator ## Run against the configured Kubernetes cluster in ~/.kube/config
$(HELM_OPERATOR) run
.PHONY: docker-build
docker-build: ## Build docker image with the manager.
docker build -t ${IMG} .
.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${IMG}
##@ Deployment
.PHONY: install
install: kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
.PHONY: uninstall
uninstall: kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl delete -f -
.PHONY: deploy
deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl delete -f -
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/ansible/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ var _ = BeforeSuite(func() {
By("updating spec of Memfin sample")
err = kbutil.ReplaceInFile(
filepath.Join(tc.Dir, "config", "samples", fmt.Sprintf("%s_%s_memfin.yaml", tc.Group, tc.Version)),
"# Add fields here",
"# TODO(user): Add fields here",
"foo: bar")
Expect(err).NotTo(HaveOccurred())

Expand All @@ -119,7 +119,7 @@ var _ = BeforeSuite(func() {
By("updating spec of Foo sample")
err = kbutil.ReplaceInFile(
filepath.Join(tc.Dir, "config", "samples", fmt.Sprintf("%s_%s_foo.yaml", tc.Group, tc.Version)),
"# Add fields here",
"# TODO(user): Add fields here",
"foo: bar")
Expect(err).NotTo(HaveOccurred())

Expand Down
9 changes: 9 additions & 0 deletions testdata/ansible/memcached-operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
# Image URL to use all building/pushing image targets
IMG ?= controller:latest

.PHONY: all
all: docker-build

##@ General
Expand All @@ -53,32 +54,40 @@ all: docker-build
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php

.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Build

.PHONY: run
run: ansible-operator ## Run against the configured Kubernetes cluster in ~/.kube/config
ANSIBLE_ROLES_PATH="$(ANSIBLE_ROLES_PATH):$(shell pwd)/roles" $(ANSIBLE_OPERATOR) run

.PHONY: docker-build
docker-build: ## Build docker image with the manager.
docker build -t ${IMG} .

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${IMG}

##@ Deployment

.PHONY: install
install: kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -

.PHONY: uninstall
uninstall: kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl delete -f -

.PHONY: deploy
deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -

.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl delete -f -

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ spec:
strategy: {}
template:
metadata:
annotations:
kubectl.kubernetes.io/default-container: manager
labels:
control-plane: controller-manager
spec:
Expand Down
Loading

0 comments on commit 67ac820

Please sign in to comment.