Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
align with kb to use common plugin instead of duplicate the code
Signed-off-by: Camila Macedo <[email protected]>
  • Loading branch information
camilamacedo86 committed Apr 7, 2021
commit c9017c26ec8944fd1f06a7932464f69444bc90aa
60 changes: 60 additions & 0 deletions changelog/fragments/add_common_kb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# entries is a list of entries to include in
# release notes and/or the migration guide
entries:
- description: >
(ansible/v1,helm/v1) Add componentConfig option. For further information check [here](https://master.book.kubebuilder.io/component-config-tutorial/tutorial.html)
kind: "addition"
breaking: false
migration:
header: (ansible/v1,helm/v1) Add componentConfig option.
body: >
To add this option your project you will need to:
- Create the file [/config/default/manager_config_patch.yaml](https://github.com/operator-framework/operator-sdk/blob/v1.6.0/testdata/ansible/memcached-operator/config/default/manager_config_patch.yaml).
- Create the file [/config/default/manager_config_patch.yaml](https://github.com/operator-framework/operator-sdk/blob/v1.6.0/testdata/ansible/memcached-operator/config/manager/controller_manager_config.yaml) .
- Update the `config/default/kustomization.yaml` by adding:
```yaml
# Mount the controller config file for loading manager configurations
# through a ComponentConfig type
#- manager_config_patch.yaml
```
- Update the `config/manager/kustomization.yaml` by adding:
```yaml
generatorOptions:
disableNameSuffixHash: true

configMapGenerator:
- files:
- controller_manager_config.yaml
name: manager-config
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: quay.io/example/memcached-operator
newTag: v0.0.1
```
- description: >
(golang/v3) Not scaffold the specific webhooks config manifests by default
kind: "bugfix"

# Is this a breaking change?
breaking: false
- description: >
(ansible/v1,helm/v1) Add rules for leader election
kind: "addition"

# Is this a breaking change?
breaking: false
migration:
header: (ansible/v1,helm/v1) Add rules for leader election.
body: >
Add the rule for the `apiGroups` `coordination.k8s.io` and the resource `leases` in config/rbac/leader_election_role.yaml:
```yaml
rules:
- apiGroups:
- ""
- coordination.k8s.io
resources:
- configmaps
- leases
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
rsc.io/letsencrypt v0.0.3 // indirect
sigs.k8s.io/controller-runtime v0.8.2
sigs.k8s.io/controller-tools v0.5.0
sigs.k8s.io/kubebuilder/v3 v3.0.0-beta.1
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20210407152553-d5e70a57ccb0
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 @@ -1557,8 +1557,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/controller-tools v0.5.0 h1:3u2RCwOlp0cjCALAigpOcbAf50pE+kHSdueUosrC/AE=
sigs.k8s.io/controller-tools v0.5.0/go.mod h1:JTsstrMpxs+9BUj6eGuAaEb6SDSPTeVtUyp0jmnAM/I=
sigs.k8s.io/kubebuilder/v3 v3.0.0-beta.1 h1:WGYvUPZ5tVrAOgvGW/NEqOXV2uYtplB6hJ/SFndrvIc=
sigs.k8s.io/kubebuilder/v3 v3.0.0-beta.1/go.mod h1:eVtLdWzmvL1ixDYLlVrvQe8wjpikJVoSOg5PghTk2Lw=
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20210407152553-d5e70a57ccb0 h1:7xXfjzq8NfOwBEo3ZGa/+G5uABPfHIDXdoy3ERn5kxQ=
sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20210407152553-d5e70a57ccb0/go.mod h1:eVtLdWzmvL1ixDYLlVrvQe8wjpikJVoSOg5PghTk2Lw=
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/kyaml v0.10.10 h1:caAxDDkaXZp+0kDsZVik4leFJV8LCy09PdVqpaoNeF4=
Expand Down
39 changes: 20 additions & 19 deletions hack/generate/samples/internal/ansible/advanced_molecule.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/operator-framework/operator-sdk/hack/generate/samples/internal/pkg"
"github.com/operator-framework/operator-sdk/internal/testutils"
"github.com/operator-framework/operator-sdk/internal/util"
)

// AdvancedMolecule defines the context for the sample
Expand Down Expand Up @@ -89,21 +90,21 @@ func (ma *AdvancedMolecule) Run() {
data:
sentinel: '{{ sentinel }}'
groups: '{{ groups | to_nice_yaml }}'`
err = testutils.ReplaceInFile(
err = util.ReplaceInFile(
inventoryRoleTask,
"# tasks file for InventoryTest",
inventoryRoleTaskFragment)
pkg.CheckError("replacing inventory task", err)

log.Infof("updating inventorytest sample")
err = testutils.ReplaceInFile(
err = util.ReplaceInFile(
filepath.Join(ma.ctx.Dir, "config", "samples", "test_v1alpha1_inventorytest.yaml"),
"name: inventorytest-sample",
inventorysampleFragment)
pkg.CheckError("updating inventorytest sample", err)

log.Infof("updating spec of inventorytest sample")
err = testutils.ReplaceInFile(
err = util.ReplaceInFile(
filepath.Join(ma.ctx.Dir, "config", "samples", "test_v1alpha1_inventorytest.yaml"),
"foo: bar",
"size: 3")
Expand Down Expand Up @@ -146,27 +147,27 @@ func (ma *AdvancedMolecule) updateConfig() {
- update
- watch
#+kubebuilder:scaffold:rules`
err := testutils.ReplaceInFile(
err := util.ReplaceInFile(
filepath.Join(ma.ctx.Dir, "config", "rbac", "role.yaml"),
"#+kubebuilder:scaffold:rules",
cmRolesFragment)
pkg.CheckError("adding customized roles", err)

log.Infof("adding manager arg")
const ansibleVaultArg = `
- "--ansible-args='--vault-password-file /opt/ansible/pwd.yml'"`
- --ansible-args='--vault-password-file /opt/ansible/pwd.yml'`
err = kbtestutils.InsertCode(
filepath.Join(ma.ctx.Dir, "config", "manager", "manager.yaml"),
"- \"--leader-election-id=advanced-molecule-operator\"",
"- --leader-election-id=advanced-molecule-operator",
ansibleVaultArg)
pkg.CheckError("adding manager arg", err)

log.Infof("adding manager env")
const managerEnv = `
- name: ANSIBLE_DEBUG_LOGS
value: "TRUE"
- name: ANSIBLE_INVENTORY
value: /opt/ansible/inventory`
- name: ANSIBLE_DEBUG_LOGS
value: "TRUE"
- name: ANSIBLE_INVENTORY
value: /opt/ansible/inventory`
err = kbtestutils.InsertCode(
filepath.Join(ma.ctx.Dir, "config", "manager", "manager.yaml"),
"value: explicit",
Expand All @@ -183,7 +184,7 @@ func (ma *AdvancedMolecule) updateConfig() {
pkg.CheckError("adding vaulting args to the proxy auth", err)

log.Infof("adding task to not pull image to the config/testing")
err = testutils.ReplaceInFile(
err = util.ReplaceInFile(
filepath.Join(ma.ctx.Dir, "config", "testing", "kustomization.yaml"),
"- manager_image.yaml",
"- manager_image.yaml\n- pull_policy/Never.yaml")
Expand Down Expand Up @@ -229,7 +230,7 @@ func (ma *AdvancedMolecule) addMocksFromTestdata() {

func (ma *AdvancedMolecule) updateDockerfile() {
log.Infof("replacing project Dockerfile to use ansible base image with the dev tag")
err := testutils.ReplaceRegexInFile(
err := util.ReplaceRegexInFile(
filepath.Join(ma.ctx.Dir, "Dockerfile"),
"quay.io/operator-framework/ansible-operator:.*",
"quay.io/operator-framework/ansible-operator:dev")
Expand Down Expand Up @@ -281,7 +282,7 @@ func (ma *AdvancedMolecule) updatePlaybooks() {
data:
msg: The decrypted value is {{the_secret.the_secret}}
`
err := testutils.ReplaceInFile(
err := util.ReplaceInFile(
filepath.Join(ma.ctx.Dir, "playbooks", "argstest.yml"),
originalPlaybookFragment,
argsPlaybook)
Expand All @@ -305,7 +306,7 @@ func (ma *AdvancedMolecule) updatePlaybooks() {
data:
shouldBeCamel: '{{ camelCaseVar | default("false") }}'
`
err = testutils.ReplaceInFile(
err = util.ReplaceInFile(
filepath.Join(ma.ctx.Dir, "playbooks", "casetest.yml"),
originalPlaybookFragment,
casePlaybook)
Expand All @@ -324,7 +325,7 @@ func (ma *AdvancedMolecule) updatePlaybooks() {
tasks:
- command: echo hello
- debug: msg='{{ "hello" | test }}'`
err = testutils.ReplaceInFile(
err = util.ReplaceInFile(
filepath.Join(ma.ctx.Dir, "playbooks", "inventorytest.yml"),
"---\n- hosts: localhost\n gather_facts: no\n collections:\n - community.kubernetes\n - operator_sdk.util\n tasks:\n - import_role:\n name: \"inventorytest\"",
inventoryPlaybook)
Expand Down Expand Up @@ -382,7 +383,7 @@ func (ma *AdvancedMolecule) updatePlaybooks() {
time: 1s
when: configmap.resources|length > 0 and (configmap.resources.0.data.iterations|int) < 5
`
err = testutils.ReplaceInFile(
err = util.ReplaceInFile(
filepath.Join(ma.ctx.Dir, "playbooks", "reconciliationtest.yml"),
originalPlaybookFragment,
reconciliationPlaybook)
Expand All @@ -406,7 +407,7 @@ func (ma *AdvancedMolecule) updatePlaybooks() {
data:
hello: "world"
`
err = testutils.ReplaceInFile(
err = util.ReplaceInFile(
filepath.Join(ma.ctx.Dir, "playbooks", "selectortest.yml"),
originalPlaybookFragment,
selectorPlaybook)
Expand Down Expand Up @@ -465,7 +466,7 @@ func (ma *AdvancedMolecule) updatePlaybooks() {
execCommandStderr: '{{ exec_result.stderr.strip() }}'
logs: '{{ log_result.log }}'
`
err = testutils.ReplaceInFile(
err = util.ReplaceInFile(
filepath.Join(ma.ctx.Dir, "playbooks", "subresourcestest.yml"),
originalPlaybookFragment,
subresourcesPlaybook)
Expand Down Expand Up @@ -497,7 +498,7 @@ func (ma *AdvancedMolecule) addPlaybooks() {
task := fmt.Sprintf("%s_test.yml", k)
logMsgForKind = fmt.Sprintf("removing FIXME assert from %s", task)
log.Infof(logMsgForKind)
err = testutils.ReplaceInFile(
err = util.ReplaceInFile(
filepath.Join(ma.ctx.Dir, "molecule", "default", "tasks", task),
fixmeAssert,
"")
Expand Down
7 changes: 4 additions & 3 deletions hack/generate/samples/internal/ansible/memcached.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/operator-framework/operator-sdk/hack/generate/samples/internal/pkg"
"github.com/operator-framework/operator-sdk/internal/testutils"
"github.com/operator-framework/operator-sdk/internal/util"
)

// MemcachedAnsible defines the context for the sample
Expand Down Expand Up @@ -91,7 +92,7 @@ func (ma *MemcachedAnsible) addingMoleculeMockData() {
moleculeTaskPath := filepath.Join(ma.ctx.Dir, "molecule", "default", "tasks",
fmt.Sprintf("%s_test.yml", strings.ToLower(ma.ctx.Kind)))

err := testutils.ReplaceInFile(moleculeTaskPath,
err := util.ReplaceInFile(moleculeTaskPath,
originaMemcachedMoleculeTask, fmt.Sprintf(moleculeTaskFragment, ma.ctx.ProjectName, ma.ctx.ProjectName))
pkg.CheckError("replacing molecule default tasks", err)
}
Expand All @@ -105,13 +106,13 @@ func (ma *MemcachedAnsible) addingAnsibleTask() {
roleFragment)
pkg.CheckError("adding task", err)

err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "roles", strings.ToLower(ma.ctx.Kind),
err = util.ReplaceInFile(filepath.Join(ma.ctx.Dir, "roles", strings.ToLower(ma.ctx.Kind),
"defaults", "main.yml"),
fmt.Sprintf("# defaults file for %s", ma.ctx.Kind),
defaultsFragment)
pkg.CheckError("adding defaulting", err)

err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "config", "samples",
err = util.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))),
"foo: bar", "size: 1")
pkg.CheckError("updating sample CR", err)
Expand Down
21 changes: 11 additions & 10 deletions hack/generate/samples/internal/ansible/memcached_molecule.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"
kbtestutils "sigs.k8s.io/kubebuilder/v3/test/e2e/utils"

"github.com/operator-framework/operator-sdk/hack/generate/samples/internal/pkg"
"github.com/operator-framework/operator-sdk/internal/testutils"
log "github.com/sirupsen/logrus"
"github.com/operator-framework/operator-sdk/internal/util"
)

// MoleculeAnsible defines the context for the sample
Expand Down Expand Up @@ -76,11 +77,11 @@ func (ma *MoleculeAnsible) Run() {
pkg.CheckError("replacing memcached task to add foo check", err)

log.Infof("replacing project Dockerfile to use ansible base image with the dev tag")
err = testutils.ReplaceRegexInFile(filepath.Join(ma.ctx.Dir, "Dockerfile"), "quay.io/operator-framework/ansible-operator:.*", "quay.io/operator-framework/ansible-operator:dev")
err = util.ReplaceRegexInFile(filepath.Join(ma.ctx.Dir, "Dockerfile"), "quay.io/operator-framework/ansible-operator:.*", "quay.io/operator-framework/ansible-operator:dev")
pkg.CheckError("replacing Dockerfile", err)

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

Expand All @@ -106,12 +107,12 @@ func (ma *MoleculeAnsible) Run() {
pkg.CheckError("creating api", err)

log.Infof("adding task to delete config map")
err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "roles", "memfin", "tasks", "main.yml"),
err = util.ReplaceInFile(filepath.Join(ma.ctx.Dir, "roles", "memfin", "tasks", "main.yml"),
"# tasks file for Memfin", taskToDeleteConfigMap)
pkg.CheckError("replacing in tasks/main.yml", err)

log.Infof("adding to watches finalizer and blacklist")
err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "watches.yaml"),
err = util.ReplaceInFile(filepath.Join(ma.ctx.Dir, "watches.yaml"),
"playbook: playbooks/memcached.yml", memcachedWatchCustomizations)
pkg.CheckError("replacing in watches", err)

Expand All @@ -133,7 +134,7 @@ func (ma *MoleculeAnsible) Run() {
pkg.CheckError("creating api", err)

log.Infof("removing ignore group for the secret from watches as an workaround to work with core types")
err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "watches.yaml"),
err = util.ReplaceInFile(filepath.Join(ma.ctx.Dir, "watches.yaml"),
"ignore.example.com", "\"\"")
pkg.CheckError("replacing the watches file", err)

Expand All @@ -143,22 +144,22 @@ func (ma *MoleculeAnsible) Run() {
pkg.CheckError("removing secret test file", err)

log.Infof("adding Secret task to the role")
err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "roles", "secret", "tasks", "main.yml"),
err = util.ReplaceInFile(filepath.Join(ma.ctx.Dir, "roles", "secret", "tasks", "main.yml"),
originalTaskSecret, taskForSecret)
pkg.CheckError("replacing in secret/tasks/main.yml file", err)

log.Infof("adding ManageStatus == false for role secret")
err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "watches.yaml"),
err = util.ReplaceInFile(filepath.Join(ma.ctx.Dir, "watches.yaml"),
"role: secret", manageStatusFalseForRoleSecret)
pkg.CheckError("replacing in watches.yaml", err)

log.Infof("removing FIXME asserts from memfin_test.yml")
err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "molecule", "default", "tasks", "memfin_test.yml"),
err = util.ReplaceInFile(filepath.Join(ma.ctx.Dir, "molecule", "default", "tasks", "memfin_test.yml"),
fixmeAssert, "")
pkg.CheckError("replacing memfin_test.yml", err)

log.Infof("removing FIXME asserts from foo_test.yml")
err = testutils.ReplaceInFile(filepath.Join(ma.ctx.Dir, "molecule", "default", "tasks", "foo_test.yml"),
err = util.ReplaceInFile(filepath.Join(ma.ctx.Dir, "molecule", "default", "tasks", "foo_test.yml"),
fixmeAssert, "")
pkg.CheckError("replacing foo_test.yml", err)
}
Expand Down
13 changes: 7 additions & 6 deletions hack/generate/samples/internal/go/v2/memcached_with_webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/operator-framework/operator-sdk/hack/generate/samples/internal/pkg"
"github.com/operator-framework/operator-sdk/internal/testutils"
"github.com/operator-framework/operator-sdk/internal/util"
)

// MemcachedGoWithWebhooks defines the Memcached Sample in GO using webhooks
Expand Down Expand Up @@ -195,7 +196,7 @@ func (mh *MemcachedGoWithWebhooks) implementingWebhooks() {
webhooksFragment)
pkg.CheckError("replacing reconcile", err)

err = testutils.ReplaceInFile(webhookPath,
err = util.ReplaceInFile(webhookPath,
"// TODO(user): fill in your defaulting logic.", "if r.Spec.Size == 0 {\n\t\tr.Spec.Size = 3\n\t}")
pkg.CheckError("replacing default webhook implementation", err)

Expand Down Expand Up @@ -224,16 +225,16 @@ func (mh *MemcachedGoWithWebhooks) implementingController() {
pkg.CheckError("adding rbac", err)

// Replace reconcile content
err = testutils.ReplaceInFile(controllerPath, "_ = context.Background()", "ctx := context.Background()")
err = util.ReplaceInFile(controllerPath, "_ = context.Background()", "ctx := context.Background()")
pkg.CheckError("replacing reconcile content", err)

err = testutils.ReplaceInFile(controllerPath,
err = util.ReplaceInFile(controllerPath,
fmt.Sprintf("_ = r.Log.WithValues(\"%s\", req.NamespacedName)", strings.ToLower(mh.ctx.Kind)),
fmt.Sprintf("log := r.Log.WithValues(\"%s\", req.NamespacedName)", strings.ToLower(mh.ctx.Kind)))
pkg.CheckError("replacing reconcile content", err)

// Add reconcile implementation
err = testutils.ReplaceInFile(controllerPath,
err = util.ReplaceInFile(controllerPath,
"// your logic here", reconcileFragment)
pkg.CheckError("replacing reconcile", err)

Expand All @@ -243,7 +244,7 @@ func (mh *MemcachedGoWithWebhooks) implementingController() {
pkg.CheckError("adding helpers methods in the controller", err)

// Add watch for the Kind
err = testutils.ReplaceInFile(controllerPath,
err = util.ReplaceInFile(controllerPath,
fmt.Sprintf(watchOriginalFragment, mh.ctx.Group, mh.ctx.Version, mh.ctx.Kind),
fmt.Sprintf(watchCustomizedFragment, mh.ctx.Group, mh.ctx.Version, mh.ctx.Kind))
pkg.CheckError("replacing reconcile", err)
Expand Down Expand Up @@ -280,7 +281,7 @@ func (mh *MemcachedGoWithWebhooks) 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 = testutils.ReplaceInFile(filepath.Join(mh.ctx.Dir, sampleFile), "foo: bar", "size: 1")
err = util.ReplaceInFile(filepath.Join(mh.ctx.Dir, sampleFile), "foo: bar", "size: 1")
pkg.CheckError("updating sample", err)
}

Expand Down
Loading