Skip to content

Commit

Permalink
remove dupliations
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed Mar 25, 2021
1 parent 4e16f40 commit 9697936
Show file tree
Hide file tree
Showing 76 changed files with 465 additions and 2,060 deletions.
16 changes: 16 additions & 0 deletions changelog/fragments/add_common_kb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# entries is a list of entries to include in
# release notes and/or the migration guide
entries:
- description: >
Add common base plugin.
# kind is one of:
# - addition
# - change
# - deprecation
# - removal
# - bugfix
kind: "addition"
# Is this a breaking change?
breaking: false
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ replace (
github.com/containerd/containerd => github.com/containerd/containerd v1.4.3
github.com/mattn/go-sqlite3 => github.com/mattn/go-sqlite3 v1.10.0
golang.org/x/text => golang.org/x/text v0.3.3 // Required to fix CVE-2020-14040
sigs.k8s.io/kubebuilder/v3 => github.com/camilamacedo86/kubebuilder/v3 v3.0.0-20210325181645-7ebc46bb648d
)

exclude github.com/spf13/viper v1.3.2 // Required to fix CVE-2018-1098
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b/go.mod h1:obH5gd0Bsq
github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
github.com/bugsnag/panicwrap v1.2.0 h1:OzrKrRvXis8qEvOkfcxNcYbOd2O7xXS2nnKMEMABFQA=
github.com/bugsnag/panicwrap v1.2.0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
github.com/camilamacedo86/kubebuilder/v3 v3.0.0-20210325181645-7ebc46bb648d h1:vYixz9WHw09qP7b3ow1UMfqj2G5Qfx04pPnCfnSAlCU=
github.com/camilamacedo86/kubebuilder/v3 v3.0.0-20210325181645-7ebc46bb648d/go.mod h1:eVtLdWzmvL1ixDYLlVrvQe8wjpikJVoSOg5PghTk2Lw=
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down Expand Up @@ -1555,8 +1557,6 @@ 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/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
27 changes: 14 additions & 13 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,7 +147,7 @@ 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)
Expand Down Expand Up @@ -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
8 changes: 5 additions & 3 deletions hack/generate/samples/internal/ansible/memcached.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"path/filepath"
"strings"

"github.com/operator-framework/operator-sdk/internal/util"

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

Expand Down Expand Up @@ -91,7 +93,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 +107,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
20 changes: 11 additions & 9 deletions hack/generate/samples/internal/ansible/memcached_molecule.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"path/filepath"
"strings"

"github.com/operator-framework/operator-sdk/internal/util"

kbtestutils "sigs.k8s.io/kubebuilder/v3/test/e2e/utils"

"github.com/operator-framework/operator-sdk/hack/generate/samples/internal/pkg"
Expand Down Expand Up @@ -76,11 +78,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 +108,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 +135,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 +145,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
11 changes: 6 additions & 5 deletions hack/generate/samples/internal/go/v3/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 webhook validate implementation", 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 webhook default implementation", err)

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

// Replace reconcile content
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 @@ -241,7 +242,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 @@ -275,7 +276,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

0 comments on commit 9697936

Please sign in to comment.