Skip to content

Commit b82a3cb

Browse files
committed
fixing generation issues
Signed-off-by: Adam D. Cornett <adc@redhat.com>
1 parent 29d59c5 commit b82a3cb

File tree

22 files changed

+113
-124
lines changed

22 files changed

+113
-124
lines changed

hack/generate/samples/ansible/advanced_molecule.go

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ func ImplementAdvancedMolecule(sample sample.Sample, image string) {
7070
"size: 3")
7171
pkg.CheckError("updating spec of inventorytest sample", err)
7272

73-
log.Info("enabling metrics in the manager")
74-
err = kbutil.UncommentCode(
75-
filepath.Join(sample.Dir(), "config", "default", "kustomization.yaml"),
76-
"#- path: manager_metrics_patch.yaml", "#")
77-
pkg.CheckError("enabling metrics endpoint", err)
73+
/* log.Info("enabling metrics in the manager")
74+
err = kbutil.UncommentCode(
75+
filepath.Join(sample.Dir(), "config", "default", "kustomization.yaml"),
76+
"#- path: manager_metrics_patch.yaml", "#")
77+
pkg.CheckError("enabling metrics endpoint", err)*/
7878

7979
removeFixmeFromPlaybooks(sample.Dir(), sample.GVKs())
8080
updatePlaybooks(sample.Dir())
@@ -84,46 +84,47 @@ func ImplementAdvancedMolecule(sample sample.Sample, image string) {
8484
}
8585

8686
func updateConfig(dir string) {
87-
log.Info("adding customized roles")
88-
const cmRolesFragment = ` ##
89-
## Base operator rules
90-
##
91-
- apiGroups:
92-
- ""
93-
resources:
94-
- configmaps
95-
- namespaces
96-
verbs:
97-
- create
98-
- delete
99-
- get
100-
- list
101-
- patch
102-
- update
103-
- watch
104-
- apiGroups:
105-
- apps
106-
resources:
107-
- configmaps
108-
verbs:
109-
- create
110-
- delete
111-
- get
112-
- list
113-
- patch
114-
- update
115-
- watch
116-
#+kubebuilder:scaffold:rules`
117-
err := kbutil.ReplaceInFile(
118-
filepath.Join(dir, "config", "rbac", "role.yaml"),
119-
"#+kubebuilder:scaffold:rules",
120-
cmRolesFragment)
121-
pkg.CheckError("adding customized roles", err)
87+
//TODO: This currently fails, unsure if we still need this, seems the role file already has this
88+
//log.Info("adding customized roles")
89+
// const cmRolesFragment = ` ##
90+
// ## Base operator rules
91+
// ##
92+
// - apiGroups:
93+
// - ""
94+
// resources:
95+
// - configmaps
96+
// - namespaces
97+
// verbs:
98+
// - create
99+
// - delete
100+
// - get
101+
// - list
102+
// - patch
103+
// - update
104+
// - watch
105+
// - apiGroups:
106+
// - apps
107+
// resources:
108+
// - configmaps
109+
// verbs:
110+
// - create
111+
// - delete
112+
// - get
113+
// - list
114+
// - patch
115+
// - update
116+
// - watch
117+
//#+kubebuilder:scaffold:rules`
118+
//err := kbutil.ReplaceInFile(
119+
// filepath.Join(dir, "config", "rbac", "role.yaml"),
120+
// "#+kubebuilder:scaffold:rules",
121+
// cmRolesFragment)
122+
//pkg.CheckError("adding customized roles", err)
122123

123124
log.Info("adding manager arg")
124125
const ansibleVaultArg = `
125126
- --ansible-args='--vault-password-file /opt/ansible/pwd.yml'`
126-
err = kbutil.InsertCode(
127+
err := kbutil.InsertCode(
127128
filepath.Join(dir, "config", "manager", "manager.yaml"),
128129
"- --leader-election-id=advanced-molecule-operator",
129130
ansibleVaultArg)
@@ -145,8 +146,8 @@ func updateConfig(dir string) {
145146
const managerAuthArgs = `
146147
- "--ansible-args='--vault-password-file /opt/ansible/pwd.yml'"`
147148
err = kbutil.InsertCode(
148-
filepath.Join(dir, "config", "default", "manager_metrics_patch.yaml"),
149-
"- \"--leader-elect\"",
149+
filepath.Join(dir, "config", "manager", "manager.yaml"),
150+
"- --leader-elect",
150151
managerAuthArgs)
151152
pkg.CheckError("adding vaulting args to the proxy auth", err)
152153

hack/generate/samples/ansible/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ const customMetricsTest = `
531531
namespace: default
532532
container: manager
533533
pod: "{{ output.resources[0].metadata.name }}"
534-
command: curl localhost:8080/metrics
534+
command: curl localhost:8443/metrics
535535
register: metrics_output
536536
537537
- name: Assert sanity metrics were created

hack/generate/samples/ansible/memcached_molecule.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func ImplementMemcachedMolecule(sample sample.Sample, image string) {
8080

8181
log.Info("adding RBAC permissions")
8282
err = kbutil.ReplaceInFile(filepath.Join(sample.Dir(), "config", "rbac", "role.yaml"),
83-
"#+kubebuilder:scaffold:rules", rolesForBaseOperator)
83+
"# +kubebuilder:scaffold:rules", rolesForBaseOperator)
8484
pkg.CheckError("replacing in role.yml", err)
8585

8686
log.Info("adding task to delete config map")
@@ -127,6 +127,6 @@ func ImplementMemcachedMolecule(sample sample.Sample, image string) {
127127
log.Info("enabling metrics in the manager")
128128
err = kbutil.UncommentCode(
129129
filepath.Join(sample.Dir(), "config", "default", "kustomization.yaml"),
130-
"#- path: manager_metrics_patch.yaml", "#")
130+
"- path: manager_metrics_patch.yaml", "#")
131131
pkg.CheckError("enabling metrics endpoint", err)
132132
}

internal/ansible/flags/flag.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ func (f *Flags) AddTo(flagSet *pflag.FlagSet) {
111111
// TODO(2.0.0): remove
112112
flagSet.StringVar(&f.MetricsBindAddress,
113113
"metrics-addr",
114-
":8080",
114+
":8443",
115115
"The address the metric endpoint binds to",
116116
)
117117
_ = flagSet.MarkDeprecated("metrics-addr", "use --metrics-bind-address instead")
118118
flagSet.StringVar(&f.MetricsBindAddress,
119119
"metrics-bind-address",
120-
":8080",
120+
":8443",
121121
"The address the metric endpoint binds to",
122122
)
123123
// TODO(2.0.0): for Go/Helm the port used is: 8081

internal/ansible/flags/flag_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var _ = Describe("Flags", func() {
5252
})
5353
When("the flag is not set", func() {
5454
It("uses the default flag value when corresponding option value is empty", func() {
55-
expOptionValue := ":8080"
55+
expOptionValue := ":8443"
5656
options.Metrics.BindAddress = ""
5757
parseArgs(flagSet)
5858
Expect(f.ToManagerOptions(options).Metrics.BindAddress).To(Equal(expOptionValue))

internal/ansible/handler/logging_enqueue_annotation_test.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2626
"k8s.io/apimachinery/pkg/runtime/schema"
2727
"k8s.io/apimachinery/pkg/types"
28+
"sigs.k8s.io/controller-runtime/pkg/client"
2829
"sigs.k8s.io/controller-runtime/pkg/controller/controllertest"
2930
"sigs.k8s.io/controller-runtime/pkg/event"
3031
"sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -60,7 +61,7 @@ var _ = Describe("LoggingEnqueueRequestForAnnotation", func() {
6061

6162
Expect(handler.SetOwnerAnnotations(podOwner, pod)).To(Succeed())
6263
instance = LoggingEnqueueRequestForAnnotation{
63-
handler.EnqueueRequestForAnnotation{
64+
handler.EnqueueRequestForAnnotation[client.Object]{
6465
Type: schema.GroupKind{
6566
Group: "",
6667
Kind: "Pod",
@@ -220,7 +221,11 @@ var _ = Describe("LoggingEnqueueRequestForAnnotation", func() {
220221
}
221222
nd.SetGroupVersionKind(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Node"})
222223

223-
instance = LoggingEnqueueRequestForAnnotation{handler.EnqueueRequestForAnnotation{Type: schema.GroupKind{Group: "apps", Kind: "ReplicaSet"}}}
224+
instance = LoggingEnqueueRequestForAnnotation{
225+
handler.EnqueueRequestForAnnotation[client.Object]{
226+
Type: schema.GroupKind{Group: "apps", Kind: "ReplicaSet"},
227+
},
228+
}
224229

225230
evt := event.CreateEvent{
226231
Object: nd,
@@ -243,7 +248,11 @@ var _ = Describe("LoggingEnqueueRequestForAnnotation", func() {
243248
}
244249
nd.SetGroupVersionKind(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Node"})
245250

246-
instance = LoggingEnqueueRequestForAnnotation{handler.EnqueueRequestForAnnotation{Type: nd.GetObjectKind().GroupVersionKind().GroupKind()}}
251+
instance = LoggingEnqueueRequestForAnnotation{
252+
handler.EnqueueRequestForAnnotation[client.Object]{
253+
Type: nd.GetObjectKind().GroupVersionKind().GroupKind(),
254+
},
255+
}
247256
evt := event.CreateEvent{
248257
Object: nd,
249258
}
@@ -341,11 +350,13 @@ var _ = Describe("LoggingEnqueueRequestForAnnotation", func() {
341350
repl.SetGroupVersionKind(schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "ReplicaSet"})
342351

343352
instance = LoggingEnqueueRequestForAnnotation{
344-
handler.EnqueueRequestForAnnotation{
353+
handler.EnqueueRequestForAnnotation[client.Object]{
345354
Type: schema.GroupKind{
346355
Group: "apps",
347356
Kind: "ReplicaSet",
348-
}}}
357+
},
358+
},
359+
}
349360

350361
evt := event.CreateEvent{
351362
Object: repl,
@@ -366,11 +377,13 @@ var _ = Describe("LoggingEnqueueRequestForAnnotation", func() {
366377
}
367378

368379
instance2 := LoggingEnqueueRequestForAnnotation{
369-
handler.EnqueueRequestForAnnotation{
380+
handler.EnqueueRequestForAnnotation[client.Object]{
370381
Type: schema.GroupKind{
371382
Group: "apps",
372383
Kind: "ReplicaSet",
373-
}}}
384+
},
385+
},
386+
}
374387

375388
evt2 := event.UpdateEvent{
376389
ObjectOld: repl,

internal/ansible/proxy/kubectl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (f *FilterServer) HandlerFor(delegate http.Handler) *FilterServer {
130130
return &f2
131131
}
132132

133-
// Get host from a host header value like "localhost" or "localhost:8080"
133+
// Get host from a host header value like "localhost" or "localhost:8443"
134134
func extractHost(header string) (host string) {
135135
host, _, err := net.SplitHostPort(header)
136136
if err != nil {

pkg/plugins/ansible/v1/init.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ func addInitCustomizations(projectName string) error {
160160
}
161161

162162
managerFile := filepath.Join("config", "manager", "manager.yaml")
163-
managerMetricsPatchFile := filepath.Join("config", "default", "manager_metrics_patch.yaml")
164163

165164
// todo: we ought to use afero instead. Replace this methods to insert/update
166165
// by https://github.com/kubernetes-sigs/kubebuilder/pull/2119
@@ -174,13 +173,6 @@ func addInitCustomizations(projectName string) error {
174173
return err
175174
}
176175

177-
err = util.InsertCode(managerMetricsPatchFile,
178-
"- \"--metrics-bind-address=0.0.0.0:8080\"",
179-
fmt.Sprintf("\n - \"--leader-elect\"\n - \"--leader-election-id=%s\"\n - \"--health-probe-bind-address=:6789\"", projectName))
180-
if err != nil {
181-
return err
182-
}
183-
184176
// update default resource request and limits with bigger values
185177
const resourcesLimitsFragment = ` resources:
186178
limits:

pkg/testutils/e2e/metrics/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func GetMetrics(sample sample.Sample, kubectl kubernetes.Kubectl, metricsCluster
1717
cmdOpts := []string{
1818
"run", "curl", "--image=curlimages/curl:7.68.0", "--restart=OnFailure", "--",
1919
"curl", "-v",
20-
fmt.Sprintf("http://%s-controller-manager-metrics-service.%s.svc:8080/metrics", sample.Name(), kubectl.Namespace()),
20+
fmt.Sprintf("http://%s-controller-manager-metrics-service.%s.svc:8443/metrics", sample.Name(), kubectl.Namespace()),
2121
}
2222
out, err := kubectl.CommandInNamespace(cmdOpts...)
2323
fmt.Println("OUT --", out)

test/e2e/ansible/suite_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@ import (
2727
. "github.com/onsi/ginkgo/v2"
2828
. "github.com/onsi/gomega"
2929

30-
kbutil "sigs.k8s.io/kubebuilder/v4/pkg/plugin/util"
31-
3230
"github.com/operator-framework/ansible-operator-plugins/hack/generate/samples/ansible"
3331
"github.com/operator-framework/ansible-operator-plugins/pkg/testutils/command"
3432
"github.com/operator-framework/ansible-operator-plugins/pkg/testutils/e2e/kind"
3533
"github.com/operator-framework/ansible-operator-plugins/pkg/testutils/e2e/operator"
3634
"github.com/operator-framework/ansible-operator-plugins/pkg/testutils/e2e/prometheus"
3735
"github.com/operator-framework/ansible-operator-plugins/pkg/testutils/kubernetes"
3836
"github.com/operator-framework/ansible-operator-plugins/pkg/testutils/sample"
37+
kbutil "sigs.k8s.io/kubebuilder/v4/pkg/plugin/util"
3938
)
4039

4140
//TODO: update this to use the new PoC api
@@ -79,8 +78,8 @@ var _ = BeforeSuite(func() {
7978
// ---------------------------------------------------
8079

8180
By("enabling debug logging in the manager")
82-
err = kbutil.ReplaceInFile(filepath.Join(ansibleSample.Dir(), "config", "default", "manager_metrics_patch.yaml"),
83-
"- \"--leader-elect\"", "- \"--zap-log-level=2\"\n - \"--leader-elect\"")
81+
err = kbutil.InsertCode(filepath.Join(ansibleSample.Dir(), "config", "manager", "manager.yaml"),
82+
"--health-probe-bind-address=:6789", "\n - --zap-log-level=2")
8483
Expect(err).NotTo(HaveOccurred())
8584

8685
// ---------------------------------------------------

0 commit comments

Comments
 (0)