Skip to content

Commit 96cb34a

Browse files
committed
fixing generation issues
Signed-off-by: Adam D. Cornett <[email protected]>
1 parent 29d59c5 commit 96cb34a

File tree

22 files changed

+108
-119
lines changed

22 files changed

+108
-119
lines changed

Diff for: hack/generate/samples/ansible/advanced_molecule.go

+39-38
Original file line numberDiff line numberDiff line change
@@ -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

Diff for: hack/generate/samples/ansible/constants.go

+1-1
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

Diff for: hack/generate/samples/ansible/memcached_molecule.go

+2-2
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
}

Diff for: internal/ansible/flags/flag.go

+2-2
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

Diff for: internal/ansible/flags/flag_test.go

+1-1
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))

Diff for: internal/ansible/handler/logging_enqueue_annotation_test.go

+20-7
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,

Diff for: internal/ansible/proxy/kubectl.go

+1-1
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 {

Diff for: pkg/plugins/ansible/v1/init.go

-8
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:

Diff for: pkg/testutils/e2e/metrics/helpers.go

+1-1
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)

Diff for: test/e2e/ansible/suite_test.go

+3-4
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
// ---------------------------------------------------

Diff for: testdata/memcached-molecule-operator/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ ifeq (,$(shell which kustomize 2>/dev/null))
8181
@{ \
8282
set -e ;\
8383
mkdir -p $(dir $(KUSTOMIZE)) ;\
84-
curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v5.3.0/kustomize_v5.3.0_$(OS)_$(ARCH).tar.gz | \
84+
curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v5.4.2/kustomize_v5.4.2_$(OS)_$(ARCH).tar.gz | \
8585
tar xzf - -C bin/ ;\
8686
}
8787
else

Diff for: testdata/memcached-molecule-operator/config/crd/kustomization.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ resources:
66
- bases/cache.example.com_foos.yaml
77
- bases/cache.example.com_memfins.yaml
88
- bases/ignore.example.com_secrets.yaml
9-
#+kubebuilder:scaffold:crdkustomizeresource
9+
# +kubebuilder:scaffold:crdkustomizeresource

Diff for: testdata/memcached-molecule-operator/config/default/kustomization.yaml

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ resources:
2020
- ../manager
2121
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
2222
- ../prometheus
23+
# [METRICS] Expose the controller manager metrics service.
24+
- metrics_service.yaml
2325

26+
# Uncomment the patches line if you enable Metrics, and/or are using webhooks and cert-manager
2427
patches:
25-
# [METRICS] The following patch will enable the metrics endpoint. Ensure that you also protect this endpoint.
28+
# [METRICS] The following patch will enable the metrics endpoint using HTTPS and the port :8443.
2629
# More info: https://book.kubebuilder.io/reference/metrics
27-
# If you want to expose the metric endpoint of your controller-manager uncomment the following line.
2830
- path: manager_metrics_patch.yaml
31+
target:
32+
kind: Deployment

Diff for: testdata/memcached-molecule-operator/config/default/manager_config_patch.yaml

-10
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
1-
# This patch adds the args to allow exposing the metrics endpoint securely
2-
apiVersion: apps/v1
3-
kind: Deployment
4-
metadata:
5-
name: controller-manager
6-
namespace: system
7-
spec:
8-
template:
9-
spec:
10-
containers:
11-
- name: manager
12-
args:
13-
- "--metrics-bind-address=0.0.0.0:8080"
14-
- "--leader-elect"
15-
- "--leader-election-id=memcached-molecule-operator"
16-
- "--health-probe-bind-address=:6789"
1+
# This patch adds the args to allow exposing the metrics endpoint using HTTPS
2+
- op: add
3+
path: /spec/template/spec/containers/0/args/0
4+
value: --metrics-bind-address=:8443

Diff for: testdata/memcached-molecule-operator/config/manager/manager.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ spec:
6262
- --leader-elect
6363
- --leader-election-id=memcached-molecule-operator
6464
- --health-probe-bind-address=:6789
65-
- --metrics-bind-address=0
6665
image: controller:latest
6766
name: manager
6867
env:

Diff for: testdata/memcached-molecule-operator/config/prometheus/monitor.yaml

+14-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,20 @@ metadata:
1111
spec:
1212
endpoints:
1313
- path: /metrics
14-
port: http # Ensure this is the name of the port that exposes HTTP metrics
15-
scheme: http
14+
port: https # Ensure this is the name of the port that exposes HTTPS metrics
15+
scheme: https
16+
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
17+
tlsConfig:
18+
# TODO(user): The option insecureSkipVerify: true is not recommended for production since it disables
19+
# certificate verification. This poses a significant security risk by making the system vulnerable to
20+
# man-in-the-middle attacks, where an attacker could intercept and manipulate the communication between
21+
# Prometheus and the monitored services. This could lead to unauthorized access to sensitive metrics data,
22+
# compromising the integrity and confidentiality of the information.
23+
# Please use the following options for secure configurations:
24+
# caFile: /etc/metrics-certs/ca.crt
25+
# certFile: /etc/metrics-certs/tls.crt
26+
# keyFile: /etc/metrics-certs/tls.key
27+
insecureSkipVerify: true
1628
selector:
1729
matchLabels:
1830
control-plane: controller-manager

Diff for: testdata/memcached-molecule-operator/config/rbac/kustomization.yaml

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ resources:
99
- role_binding.yaml
1010
- leader_election_role.yaml
1111
- leader_election_role_binding.yaml
12-
- metrics_service.yaml
12+
# The following RBAC configurations are used to protect
13+
# the metrics endpoint with authn/authz. These configurations
14+
# ensure that only authorized users and service accounts
15+
# can access the metrics endpoint. Comment the following
16+
# permissions if you want to disable this protection.
17+
# More info: https://book.kubebuilder.io/reference/metrics.html
18+
- metrics_auth_role.yaml
19+
- metrics_auth_role_binding.yaml
20+
- metrics_reader_role.yaml
1321
# For each CRD, "Editor" and "Viewer" roles are scaffolded by
1422
# default, aiding admins in cluster management. Those roles are
1523
# not used by the Project itself. You can comment the following lines

0 commit comments

Comments
 (0)