Skip to content

Commit

Permalink
adopt controller-runtime 0.16.0 and update code generators
Browse files Browse the repository at this point in the history
  • Loading branch information
cbarbian-sap committed Aug 31, 2023
1 parent 9e8a6fa commit 715baad
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 45 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ LISTER_GEN ?= $(shell pwd)/bin/lister-gen

## Tool Versions
KUSTOMIZE_VERSION ?= v4.5.5
CONTROLLER_TOOLS_VERSION ?= v0.9.2
CODE_GENERATOR_VERSION ?= v0.23.4
CONTROLLER_TOOLS_VERSION ?= v0.13.0
CODE_GENERATOR_VERSION ?= v0.28.1

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
Expand Down
1 change: 0 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 20 additions & 6 deletions internal/controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/envtest"
ctrllog "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"

dnsv1alpha1 "github.com/sap/dns-masquerading-operator/api/v1alpha1"
"github.com/sap/dns-masquerading-operator/internal/controllers"
Expand Down Expand Up @@ -226,13 +228,25 @@ var _ = BeforeSuite(func() {

By("creating manager")
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
MetricsBindAddress: "0",
Scheme: scheme,
Client: client.Options{
Cache: &client.CacheOptions{
DisableFor: []client.Object{
&dnsv1alpha1.MasqueradingRule{},
&corev1.ConfigMap{},
},
},
},
WebhookServer: webhook.NewServer(webhook.Options{
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
}),
Metrics: metricsserver.Options{
BindAddress: "0",
},
HealthProbeBindAddress: "0",
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
ClientDisableCacheFor: []client.Object{&dnsv1alpha1.MasqueradingRule{}}})
})
Expect(err).NotTo(HaveOccurred())

err = (&controllers.MasqueradingRuleReconciler{
Expand Down
45 changes: 28 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"

dnsv1alpha1 "github.com/sap/dns-masquerading-operator/api/v1alpha1"
"github.com/sap/dns-masquerading-operator/internal/controllers"
Expand Down Expand Up @@ -93,7 +95,7 @@ func main() {
os.Exit(1)
}

host, port, err := parseAddress(webhookAddr)
webhookHost, webhookPort, err := parseAddress(webhookAddr)
if err != nil {
setupLog.Error(err, "unable to parse webhook bind address")
os.Exit(1)
Expand All @@ -110,18 +112,27 @@ func main() {

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
ClientDisableCacheFor: []client.Object{
&dnsv1alpha1.MasqueradingRule{},
&corev1.ConfigMap{},
Client: client.Options{
Cache: &client.CacheOptions{
DisableFor: []client.Object{
&dnsv1alpha1.MasqueradingRule{},
&corev1.ConfigMap{},
},
},
},
MetricsBindAddress: metricsAddr,
HealthProbeBindAddress: probeAddr,
Host: host,
Port: int(port),
LeaderElection: enableLeaderElection,
LeaderElectionNamespace: leaderElectionNamespace,
LeaderElectionID: LeaderElectionID,
CertDir: webhookCertDir,
LeaderElection: enableLeaderElection,
LeaderElectionNamespace: leaderElectionNamespace,
LeaderElectionID: LeaderElectionID,
LeaderElectionReleaseOnCancel: true,
WebhookServer: webhook.NewServer(webhook.Options{
Host: webhookHost,
Port: webhookPort,
CertDir: webhookCertDir,
}),
Metrics: metricsserver.Options{
BindAddress: metricsAddr,
},
HealthProbeBindAddress: probeAddr,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down Expand Up @@ -192,16 +203,16 @@ func main() {
}
}

func parseAddress(address string) (string, uint16, error) {
func parseAddress(address string) (string, int, error) {
host, p, err := net.SplitHostPort(address)
if err != nil {
return "", 0, err
return "", -1, err
}
port, err := strconv.ParseUint(p, 10, 16)
port, err := strconv.Atoi(p)
if err != nil {
return "", 0, err
return "", -1, err
}
return host, uint16(port), nil
return host, port, nil
}

func checkInCluster() (bool, string, error) {
Expand Down
7 changes: 5 additions & 2 deletions pkg/client/clientset/versioned/clientset.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions pkg/client/clientset/versioned/doc.go

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 76 additions & 5 deletions pkg/client/informers/externalversions/factory.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 715baad

Please sign in to comment.