Skip to content

Commit

Permalink
update kb dep and get bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Camila Macedo committed Jan 18, 2021
1 parent 57567a1 commit 7eaff31
Show file tree
Hide file tree
Showing 54 changed files with 299 additions and 180 deletions.
66 changes: 66 additions & 0 deletions changelog/fragments/kb-1001d36a1bab.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# entries is a list of entries to include in
# release notes and/or the migration guide
entries:
- description: >
For Go-based operators, fix layout of the PROJECT file that stores the resources. More info: [#kubernetes-sigs/kubebuilder#1899](https://github.com/kubernetes-sigs/kubebuilder/pull/1899).
kind: "bugfix"
breaking: true
migration:
header: Fix data scaffolded in PROJECT file
body: >
It is valid only for projects scaffolded with SDK 1.3.0 release or that was upgraded to go/v3 using the changes of this release.
In the PROJECT file, replace `- crdVersion: <crdVersion>` with `- api.crdVersion: <crdVersion>` and `webhookVersion: <webhookVersion>` with `webhooks.webhookVersion: <webhookVersion>`. Ensure that the resources in your project file results are like:
```yml
resources:
- api:
crdVersion: v1
group: cache
kind: Memcached
version: v1alpha1
webhooks:
webhookVersion: v1
```
- description: >
Remove spaces from maker comments to make them machine-readable. More info: [#kubernetes-sigs/kubebuilder#1868](https://github.com/kubernetes-sigs/kubebuilder/pull/1868).
kind: "bugfix"
breaking: false
migration:
header: Update the comments makers of your project to make them machibe redable.
body: >
Update your project files removing the maker's comments spaces as follows:
- Replace `# +kubebuilder` with `#+kubebuilder`
- Replace `// +groupName` with `//+groupName`
- description: >
Add help option for operator projects scaffolded with the tool.
kind: "addition"
breaking: false
migration:
header: Update your Makefile to have a help command for your project helpers
body: >
You can check the Makefile files of the testdata samples in the tag release branch to know how you can update
your Makefile accordingly to have an help option. See: https://github.com/operator-framework/operator-sdk/tree/v1.4.x/testdata
- description: >
Add support for markers for files with the `yml` extension. More info: [#kubernetes-sigs/kubebuilder#1907](https://github.com/kubernetes-sigs/kubebuilder/pull/1907).
kind: "addition"
breaking: false
- description: >
For Go-based operators using go/v3 plugin only, add the `--force` option to the `create webhook` command. More info: [#kubernetes-sigs/kubebuilder#1903](https://github.com/kubernetes-sigs/kubebuilder/pull/1903).
kind: "addition"
breaking: false
- description: >
For Go-based operators, fix `--force` option to recreate the files via `create api` command. More info: [#kubernetes-sigs/kubebuilder#1903](https://github.com/kubernetes-sigs/kubebuilder/pull/1903).
kind: "bugfix"
breaking: false
- description: >
For Go-based operators using go/v3 plugin only, upgrade the sigs.k8s.io/kubebuilder-declarative-pattern dependency (used only to gen api with --pattern=addon). More info: [#kubernetes-sigs/kubebuilder#1946](https://github.com/kubernetes-sigs/kubebuilder/pull/1946).
kind: "change"
breaking: false
- description: >
For Go-based operators, fix the name of the files to be edit in the comments of `[kind]_types.go` files. More info: [#kubernetes-sigs/kubebuilder#1927](https://github.com/kubernetes-sigs/kubebuilder/pull/1927).
kind: "bugfix"
breaking: false
header: Fix the name of the files in the comments on the `<kind>_types.go` files
body: >
When we use `$operator-sdk create api` or `$operator-sdk create webhook`, it generates a file like `[kind]_types.go`. In this file, there is a comment that indicates which file to change when adding a field.
You can update it with the correct value if you wich by replacing the Kind for lower case, such as replace `Edit Memcached_types.go to remove/update` with `Edit memcached_types.go to remove/update`
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ require (
rsc.io/letsencrypt v0.0.3 // indirect
sigs.k8s.io/controller-runtime v0.7.0
sigs.k8s.io/controller-tools v0.4.1
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20201214213149-0a807f4e9428
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20210115025352-1001d36a1bab
sigs.k8s.io/yaml v1.2.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,8 @@ sigs.k8s.io/controller-tools v0.4.1 h1:VkuV0MxlRPmRu5iTgBZU4UxUX2LiR99n3sdQGRxZF
sigs.k8s.io/controller-tools v0.4.1/go.mod h1:G9rHdZMVlBDocIxGkK3jHLWqcTMNvveypYJwrvYKjWU=
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20201214213149-0a807f4e9428 h1:VUvP/g8pDUdqBHgKPoSX6WA/ZH1Y1+FBOk7khgyTLJw=
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20201214213149-0a807f4e9428/go.mod h1:J/D/179LBZhQOhRvmMRNbje/Bk+PjbN0/fzUupmO7+U=
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20210115025352-1001d36a1bab h1:lm8VpFSAei4cCjKPWN8326qeyswxpFrYFOEcMRD5lP4=
sigs.k8s.io/kubebuilder/v2 v2.3.2-0.20210115025352-1001d36a1bab/go.mod h1:J/D/179LBZhQOhRvmMRNbje/Bk+PjbN0/fzUupmO7+U=
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/structured-merge-diff/v3 v3.0.0-20200116222232-67a7b8c61874/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw=
Expand Down
4 changes: 2 additions & 2 deletions hack/generate/samples/internal/ansible/advanced_molecule.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ func (ma *AdvancedMolecule) updateConfig() {
- patch
- update
- watch
# +kubebuilder:scaffold:rules`
#+kubebuilder:scaffold:rules`
err := testutils.ReplaceInFile(
filepath.Join(ma.ctx.Dir, "config", "rbac", "role.yaml"),
"# +kubebuilder:scaffold:rules",
"#+kubebuilder:scaffold:rules",
cmRolesFragment)
pkg.CheckError("adding customized roles", err)

Expand Down
2 changes: 1 addition & 1 deletion hack/generate/samples/internal/ansible/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,5 +379,5 @@ const rolesForBaseOperator = `
- patch
- update
- watch
# +kubebuilder:scaffold:rules
#+kubebuilder:scaffold:rules
`
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (ma *MoleculeAnsible) Run() {

log.Infof("adding RBAC permissions")
err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "config", "rbac", "role.yaml"),
"# +kubebuilder:scaffold:rules", rolesForBaseOperator)
"#+kubebuilder:scaffold:rules", rolesForBaseOperator)
pkg.CheckError("replacing in role.yml", err)

log.Infof("adding Memcached mock task to the role with black list")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@
playbook: playbooks/reconciliationtest.yml
vars:
meta: '{{ ansible_operator_meta }}'
# +kubebuilder:scaffold:watch
#+kubebuilder:scaffold:watch
4 changes: 2 additions & 2 deletions hack/generate/samples/internal/helm/memcached.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (mh *MemcachedHelm) Run() {

log.Infof("adding customized roles")
err = testutils.ReplaceInFile(filepath.Join(mh.ctx.Dir, "config", "rbac", "role.yaml"),
"# +kubebuilder:scaffold:rules", policyRolesFragment)
"#+kubebuilder:scaffold:rules", policyRolesFragment)
pkg.CheckError("adding customized roles", err)

log.Infof("creating the bundle")
Expand Down Expand Up @@ -151,5 +151,5 @@ const policyRolesFragment = `
- update
- watch
# +kubebuilder:scaffold:rules
#+kubebuilder:scaffold:rules
`
2 changes: 1 addition & 1 deletion internal/plugins/ansible/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (p *createAPIPSubcommand) Run() error {
// SDK phase 2 plugins.
func (p *createAPIPSubcommand) runPhase2() error {
gvk := p.createOptions.GVK
return manifests.RunCreateAPI(p.config, config.GVK{Group: gvk.Group, Version: gvk.Version, Kind: gvk.Kind})
return manifests.RunCreateAPI(p.config, config.ResourceData{Group: gvk.Group, Version: gvk.Version, Kind: gvk.Kind})
}

func (p *createAPIPSubcommand) Validate() error {
Expand Down
6 changes: 4 additions & 2 deletions internal/plugins/ansible/v1/scaffolds/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ func (s *apiScaffolder) scaffold() error {
Kind: s.opts.GVK.Kind,
}

if s.config.HasResource(resourceOptions.GVK()) {
// Check that resource doesn't exist
res := s.config.GetResource(resourceOptions.Data())
if res != nil && res.API != nil {
return errors.New("the API resource already exists")
}

Expand All @@ -91,7 +93,7 @@ func (s *apiScaffolder) scaffold() error {
}

resource := resourceOptions.NewResource(s.config, true)
s.config.UpdateResources(resource.GVK())
s.config.UpdateResources(resource.Data())

var createAPITemplates []file.Builder
createAPITemplates = append(createAPITemplates,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,43 @@ IMG ?= {{ .Image }}
all: docker-build
# Run against the configured Kubernetes cluster in ~/.kube/config
run: ansible-operator
##@ Targets
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# 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)
run: ansible-operator ## Run a controller from your host.
$(ANSIBLE_OPERATOR) run
# Install CRDs into a cluster
install: kustomize
install: kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
# Uninstall CRDs from a cluster
uninstall: kustomize
uninstall: kustomize ## Uninstall CRDs from a cluster
$(KUSTOMIZE) build config/crd | kubectl delete -f -
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: kustomize
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 -
# Undeploy controller in the configured Kubernetes cluster in ~/.kube/config
undeploy: kustomize
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl delete -f -
# Build the docker image
docker-build:
docker-build: ## Build the docker image for the controller.
docker build . -t ${IMG}
# Push the docker image
docker-push:
docker-push: ## Push the docker image for the controller.
docker push ${IMG}
PATH := $(PATH):$(PWD)/bin
Expand All @@ -106,7 +116,7 @@ ARCH = $(shell uname -m | sed 's/x86_64/amd64/')
OSOPER = $(shell uname -s | tr '[:upper:]' '[:lower:]' | sed 's/darwin/apple-darwin/' | sed 's/linux/linux-gnu/')
ARCHOPER = $(shell uname -m )
kustomize:
kustomize: ## Download kustomize locally if necessary.
ifeq (, $(shell which kustomize 2>/dev/null))
@{ \
set -e ;\
Expand All @@ -118,7 +128,7 @@ else
KUSTOMIZE=$(shell which kustomize)
endif
ansible-operator:
ansible-operator: ## Download ansible-operator binary locally if necessary.
ifeq (, $(shell which ansible-operator 2>/dev/null))
@{ \
set -e ;\
Expand Down
6 changes: 3 additions & 3 deletions internal/plugins/golang/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (p *createAPISubcommand) InjectConfig(c *config.Config) {

func (p *createAPISubcommand) Run() error {
// Run() may add a new resource to the config, so we can compare resources before/after to get the new resource.
oldResources := make(map[config.GVK]struct{}, len(p.config.Resources))
oldResources := make(map[config.ResourceData]struct{}, len(p.config.Resources))
for _, r := range p.config.Resources {
oldResources[r] = struct{}{}
}
Expand All @@ -57,7 +57,7 @@ func (p *createAPISubcommand) Run() error {

// Find the new resource. Here we shouldn't worry about checking if one was found,
// since downstream plugins will do so.
var newResource config.GVK
var newResource config.ResourceData
for _, r := range p.config.Resources {
if _, hasResource := oldResources[r]; !hasResource {
newResource = r
Expand All @@ -70,6 +70,6 @@ func (p *createAPISubcommand) Run() error {
}

// SDK phase 2 plugins.
func (p *createAPISubcommand) runPhase2(gvk config.GVK) error {
func (p *createAPISubcommand) runPhase2(gvk config.ResourceData) error {
return manifests.RunCreateAPI(p.config, gvk)
}
6 changes: 3 additions & 3 deletions internal/plugins/golang/v3/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (p *createAPISubcommand) InjectConfig(c *config.Config) {

func (p *createAPISubcommand) Run() error {
// Run() may add a new resource to the config, so we can compare resources before/after to get the new resource.
oldResources := make(map[config.GVK]struct{}, len(p.config.Resources))
oldResources := make(map[config.ResourceData]struct{}, len(p.config.Resources))
for _, r := range p.config.Resources {
oldResources[r] = struct{}{}
}
Expand All @@ -52,7 +52,7 @@ func (p *createAPISubcommand) Run() error {

// Find the new resource. Here we shouldn't worry about checking if one was found,
// since downstream plugins will do so.
var newResource config.GVK
var newResource config.ResourceData
for _, r := range p.config.Resources {
if _, hasResource := oldResources[r]; !hasResource {
newResource = r
Expand All @@ -65,6 +65,6 @@ func (p *createAPISubcommand) Run() error {
}

// SDK phase 2 plugins.
func (p *createAPISubcommand) runPhase2(gvk config.GVK) error {
func (p *createAPISubcommand) runPhase2(gvk config.ResourceData) error {
return manifestsv2.RunCreateAPI(p.config, gvk)
}
2 changes: 1 addition & 1 deletion internal/plugins/helm/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (p *createAPISubcommand) Run() error {
// SDK phase 2 plugins.
func (p *createAPISubcommand) runPhase2() error {
gvk := p.createOptions.GVK
return manifests.RunCreateAPI(p.config, config.GVK{Group: gvk.Group, Version: gvk.Version, Kind: gvk.Kind})
return manifests.RunCreateAPI(p.config, config.ResourceData{Group: gvk.Group, Version: gvk.Version, Kind: gvk.Kind})
}

// Validate perform the required validations for this plugin
Expand Down
9 changes: 5 additions & 4 deletions internal/plugins/helm/v1/scaffolds/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,21 @@ func (s *apiScaffolder) scaffold() error {
}

// Check that resource doesn't exist
if s.config.HasResource(r.GVK()) {
res := s.config.GetResource(r.Data())
if res != nil && res.API != nil {
return errors.New("the API resource already exists")
}
// Check that the provided group can be added to the project
if !s.config.MultiGroup && len(s.config.Resources) != 0 && !s.config.HasGroup(r.Group) {
return errors.New("multiple groups are not allowed by default, to enable multi-group set 'multigroup: true' in your PROJECT file")
}

res := r.NewResource(s.config, true)
s.config.UpdateResources(res.GVK())
resource := r.NewResource(s.config, true)
s.config.UpdateResources(resource.Data())

chartPath := filepath.Join(chartutil.HelmChartsDir, chrt.Metadata.Name)
if err := machinery.NewScaffold().Execute(
s.newUniverse(res),
s.newUniverse(resource),
&templates.WatchesUpdater{ChartPath: chartPath},
&crd.CRD{CRDVersion: s.opts.CRDVersion},
&crd.Kustomization{},
Expand Down
Loading

0 comments on commit 7eaff31

Please sign in to comment.