Skip to content

Commit

Permalink
Fix sanity tests
Browse files Browse the repository at this point in the history
* Remove kube-rbac-proxy.
* Remove component config support.
* Regenerate test-data
  • Loading branch information
Neo2308 committed Jun 18, 2024
1 parent a2717d4 commit 4d76fbd
Show file tree
Hide file tree
Showing 26 changed files with 95 additions and 300 deletions.
10 changes: 2 additions & 8 deletions pkg/plugins/helm/v1/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,10 @@ func addInitCustomizations(projectName string) error {
// todo: we ought to use afero instead. Replace this methods to insert/update
// by https://github.com/kubernetes-sigs/kubebuilder/pull/2119

// Add leader election arg in config/manager/manager.yaml and in config/default/manager_auth_proxy_patch.yaml
// Add leader election arg in config/manager/manager.yaml
err := kbutils.InsertCode(managerFile,
"--leader-elect",
fmt.Sprintf("\n - --leader-election-id=%s", projectName))
if err != nil {
return err
}
err = kbutils.InsertCode(filepath.Join("config", "default", "manager_auth_proxy_patch.yaml"),
"- \"--leader-elect\"",
fmt.Sprintf("\n - \"--leader-election-id=%s\"", projectName))
fmt.Sprintf("\n - --leader-election-id=%s", projectName))
if err != nil {
return err
}
Expand Down
10 changes: 2 additions & 8 deletions pkg/plugins/hybrid/v1alpha/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,10 @@ func addInitCustomizations(projectName string) error {
// todo: we ought to use afero instead. Replace this methods to insert/update
// by https://github.com/kubernetes-sigs/kubebuilder/pull/2119

// Add leader election arg in config/manager/manager.yaml and in config/default/manager_auth_proxy_patch.yaml
// Add leader election arg in config/manager/manager.yaml
err := util.InsertCode(managerFile,
"--leader-elect",
fmt.Sprintf("\n - --leader-election-id=%s", projectName))
if err != nil {
return err
}
err = util.InsertCode(filepath.Join("config", "default", "manager_auth_proxy_patch.yaml"),
"- \"--leader-elect\"",
fmt.Sprintf("\n - \"--leader-election-id=%s\"", projectName))
fmt.Sprintf("\n - --leader-election-id=%s", projectName))
if err != nil {
return err
}
Expand Down
22 changes: 0 additions & 22 deletions pkg/plugins/hybrid/v1alpha/scaffolds/internal/templates/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ func init() {
}
func main() {
{{- if not .ComponentConfig }}
var (
metricsAddr string
leaderElectionID string
Expand All @@ -248,13 +247,6 @@ func main() {
"Whether or not the metrics endpoint should be served securely")
flag.BoolVar(&enableHTTP2, "enable-http2", false,
"Whether or not HTTP/2 should be enabled for the metrics and webhook servers")
{{- else }}
var configFile string
flag.StringVar(&configFile, "config", "",
"The controller will load its initial configuration from this file. " +
"Omit this flag to use the default configuration values. " +
"Command-line flags override configuration from this file.")
{{- end }}
opts := zap.Options{
Development: true,
}
Expand All @@ -263,7 +255,6 @@ func main() {
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
{{ if not .ComponentConfig }}
disableHTTP2 := func(c *tls.Config) {
setupLog.Info("disabling http/2")
c.NextProtos = []string{"http/1.1"}
Expand All @@ -290,19 +281,6 @@ func main() {
LeaderElection: enableLeaderElection,
LeaderElectionID: leaderElectionID,
})
{{- else }}
var err error
options := ctrl.Options{Scheme: scheme}
if configFile != "" {
options, err = options.AndFrom(ctrl.ConfigFile().AtPath(configFile))
if err != nil {
setupLog.Error(err, "unable to load the config file")
os.Exit(1)
}
}
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), options)
{{- end }}
if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions testdata/hybrid/memcached-operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest

## Tool Versions
KUSTOMIZE_VERSION ?= v5.3.0
CONTROLLER_TOOLS_VERSION ?= v0.14.0
KUSTOMIZE_VERSION ?= v5.4.1
CONTROLLER_TOOLS_VERSION ?= v0.15.0

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type MemcachedStatus struct {
// Important: Run "make" to regenerate code after modifying this file
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// Memcached is the Schema for the memcacheds API
type Memcached struct {
Expand All @@ -50,7 +50,7 @@ type Memcached struct {
Status MemcachedStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
// +kubebuilder:object:root=true

// MemcachedList contains a list of Memcached
type MemcachedList struct {
Expand Down
6 changes: 3 additions & 3 deletions testdata/hybrid/memcached-operator/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (

cachev1alpha1 "github.com/example/memcached-operator/api/v1alpha1"
"github.com/example/memcached-operator/internal/controller"
//+kubebuilder:scaffold:imports
// +kubebuilder:scaffold:imports
)

var (
Expand All @@ -54,7 +54,7 @@ func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))

utilruntime.Must(cachev1alpha1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
// +kubebuilder:scaffold:scheme
}

func main() {
Expand Down Expand Up @@ -125,7 +125,7 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Memcached")
os.Exit(1)
}
//+kubebuilder:scaffold:builder
// +kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ resources:
- ../manager
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
#- ../prometheus
# [METRICS] To enable the controller manager metrics service, uncomment the following line.
#- metrics_service.yaml

patches:
# Protect the /metrics endpoint by putting it behind auth.
# If you want your controller-manager to expose the /metrics
# endpoint w/o any authn/z, please comment the following line.
- path: manager_auth_proxy_patch.yaml
# Uncomment the patches line if you enable Metrics, and/or are using webhooks and cert-manager
#patches:
# [METRICS] The following patch will enable the metrics endpoint. Ensure that you also protect this endpoint.
# More info: https://book.kubebuilder.io/reference/metrics
# If you want to expose the metric endpoint of your controller-manager uncomment the following line.
#- path: manager_metrics_patch.yaml
# target:
# kind: Deployment

This file was deleted.

This file was deleted.

17 changes: 5 additions & 12 deletions testdata/hybrid/memcached-operator/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ kind: Namespace
metadata:
labels:
control-plane: controller-manager
app.kubernetes.io/name: namespace
app.kubernetes.io/instance: system
app.kubernetes.io/component: manager
app.kubernetes.io/created-by: memcached-operator
app.kubernetes.io/part-of: memcached-operator
app.kubernetes.io/name: memcached-operator
app.kubernetes.io/managed-by: kustomize
name: system
---
Expand All @@ -18,11 +14,7 @@ metadata:
namespace: system
labels:
control-plane: controller-manager
app.kubernetes.io/name: deployment
app.kubernetes.io/instance: controller-manager
app.kubernetes.io/component: manager
app.kubernetes.io/created-by: memcached-operator
app.kubernetes.io/part-of: memcached-operator
app.kubernetes.io/name: memcached-operator
app.kubernetes.io/managed-by: kustomize
spec:
selector:
Expand Down Expand Up @@ -67,8 +59,9 @@ spec:
# type: RuntimeDefault
containers:
- args:
- --leader-elect
- --leader-election-id=memcached-operator
- --leader-elect
- --leader-election-id=memcached-operator
- --health-probe-bind-address=:8081
image: controller:latest
name: manager
securityContext:
Expand Down
13 changes: 3 additions & 10 deletions testdata/hybrid/memcached-operator/config/prometheus/monitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@ kind: ServiceMonitor
metadata:
labels:
control-plane: controller-manager
app.kubernetes.io/name: servicemonitor
app.kubernetes.io/instance: controller-manager-metrics-monitor
app.kubernetes.io/component: metrics
app.kubernetes.io/created-by: memcached-operator
app.kubernetes.io/part-of: memcached-operator
app.kubernetes.io/name: memcached-operator
app.kubernetes.io/managed-by: kustomize
name: controller-manager-metrics-monitor
namespace: system
spec:
endpoints:
- path: /metrics
port: https
scheme: https
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
tlsConfig:
insecureSkipVerify: true
port: http # Ensure this is the name of the port that exposes HTTP metrics
scheme: http
selector:
matchLabels:
control-plane: controller-manager

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,3 @@ resources:
- role_binding.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml
# Comment the following 4 lines if you want to disable
# the auth proxy (https://github.com/brancz/kube-rbac-proxy)
# which protects your /metrics endpoint.
- auth_proxy_service.yaml
- auth_proxy_role.yaml
- auth_proxy_role_binding.yaml
- auth_proxy_client_clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
labels:
app.kubernetes.io/name: role
app.kubernetes.io/instance: leader-election-role
app.kubernetes.io/component: rbac
app.kubernetes.io/created-by: memcached-operator
app.kubernetes.io/part-of: memcached-operator
app.kubernetes.io/name: memcached-operator
app.kubernetes.io/managed-by: kustomize
name: leader-election-role
rules:
Expand Down
Loading

0 comments on commit 4d76fbd

Please sign in to comment.