Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed Dec 1, 2024
1 parent 323eb3e commit 72ee944
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 61 deletions.
39 changes: 30 additions & 9 deletions docs/book/src/cronjob-tutorial/testdata/project/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/certwatcher"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
Expand All @@ -54,8 +55,9 @@ Builtin types such as Job have their scheme added by `clientgoscheme`.
*/

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
certWatcher *certwatcher.CertWatcher
)

func init() {
Expand Down Expand Up @@ -144,15 +146,25 @@ func main() {
// for the metrics server, suitable for development but not recommended for production.
// To use cert-manager-managed certificates, enable [METRICS WITH CERTMANAGER] in
// config/default/kustomization.yaml and specify CertDir, CertName, and KeyName accordingly.
if certDir != "" {
metricsServerOptions.CertDir = certDir
}

if certName != "" && certKey != "" {
metricsServerOptions.CertName = certName
metricsServerOptions.KeyName = certKey
setupLog.Info("using certName and certKey for the metrics server", "certName", certName, "certKey", certKey)
var err error
certWatcher, err = certwatcher.New(certName, certKey)
if err != nil {
setupLog.Error(err, "to initialize certificate watcher", "error", err)
os.Exit(1)
}

metricsServerOptions.TLSOpts = append(metricsServerOptions.TLSOpts, func(config *tls.Config) {
config.GetCertificate = certWatcher.GetCertificate
})
} else if certDir != "" {
setupLog.Info("using CertDir for the metrics server. ", "certDir", certDir)
metricsServerOptions.CertDir = certDir
} else {
setupLog.Info("Using self-signed certificates for the metrics server." +
"Consider informing the metrics server with your own certificates by setting CertDir or CertName and KeyName.")
}

}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Expand Down Expand Up @@ -206,6 +218,15 @@ func main() {
}
// +kubebuilder:scaffold:builder

// Add Certificate Watcher to Manager
if certWatcher != nil {
setupLog.Info("Adding certificate watcher to manager")
if err := mgr.Add(certWatcher); err != nil {
setupLog.Error(err, "Failed to add certificate watcher to manager")
os.Exit(1)
}
}

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
Expand Down
39 changes: 30 additions & 9 deletions docs/book/src/getting-started/testdata/project/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/certwatcher"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
Expand All @@ -41,8 +42,9 @@ import (
)

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
certWatcher *certwatcher.CertWatcher
)

func init() {
Expand Down Expand Up @@ -124,15 +126,25 @@ func main() {
// for the metrics server, suitable for development but not recommended for production.
// To use cert-manager-managed certificates, enable [METRICS WITH CERTMANAGER] in
// config/default/kustomization.yaml and specify CertDir, CertName, and KeyName accordingly.
if certDir != "" {
metricsServerOptions.CertDir = certDir
}

if certName != "" && certKey != "" {
metricsServerOptions.CertName = certName
metricsServerOptions.KeyName = certKey
setupLog.Info("using certName and certKey for the metrics server", "certName", certName, "certKey", certKey)
var err error
certWatcher, err = certwatcher.New(certName, certKey)
if err != nil {
setupLog.Error(err, "to initialize certificate watcher", "error", err)
os.Exit(1)
}

metricsServerOptions.TLSOpts = append(metricsServerOptions.TLSOpts, func(config *tls.Config) {
config.GetCertificate = certWatcher.GetCertificate
})
} else if certDir != "" {
setupLog.Info("using CertDir for the metrics server. ", "certDir", certDir)
metricsServerOptions.CertDir = certDir
} else {
setupLog.Info("Using self-signed certificates for the metrics server." +
"Consider informing the metrics server with your own certificates by setting CertDir or CertName and KeyName.")
}

}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Expand Down Expand Up @@ -168,6 +180,15 @@ func main() {
}
// +kubebuilder:scaffold:builder

// Add Certificate Watcher to Manager
if certWatcher != nil {
setupLog.Info("Adding certificate watcher to manager")
if err := mgr.Add(certWatcher); err != nil {
setupLog.Error(err, "Failed to add certificate watcher to manager")
os.Exit(1)
}
}

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
Expand Down
39 changes: 30 additions & 9 deletions docs/book/src/multiversion-tutorial/testdata/project/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/certwatcher"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
Expand All @@ -51,8 +52,9 @@ import (
*/

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
certWatcher *certwatcher.CertWatcher
)

func init() {
Expand Down Expand Up @@ -143,15 +145,25 @@ func main() {
// for the metrics server, suitable for development but not recommended for production.
// To use cert-manager-managed certificates, enable [METRICS WITH CERTMANAGER] in
// config/default/kustomization.yaml and specify CertDir, CertName, and KeyName accordingly.
if certDir != "" {
metricsServerOptions.CertDir = certDir
}

if certName != "" && certKey != "" {
metricsServerOptions.CertName = certName
metricsServerOptions.KeyName = certKey
setupLog.Info("using certName and certKey for the metrics server", "certName", certName, "certKey", certKey)
var err error
certWatcher, err = certwatcher.New(certName, certKey)
if err != nil {
setupLog.Error(err, "to initialize certificate watcher", "error", err)
os.Exit(1)
}

metricsServerOptions.TLSOpts = append(metricsServerOptions.TLSOpts, func(config *tls.Config) {
config.GetCertificate = certWatcher.GetCertificate
})
} else if certDir != "" {
setupLog.Info("using CertDir for the metrics server. ", "certDir", certDir)
metricsServerOptions.CertDir = certDir
} else {
setupLog.Info("Using self-signed certificates for the metrics server." +
"Consider informing the metrics server with your own certificates by setting CertDir or CertName and KeyName.")
}

}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Expand Down Expand Up @@ -209,6 +221,15 @@ func main() {
/*
*/

// Add Certificate Watcher to Manager
if certWatcher != nil {
setupLog.Info("Adding certificate watcher to manager")
if err := mgr.Add(certWatcher); err != nil {
setupLog.Error(err, "Failed to add certificate watcher to manager")
os.Exit(1)
}
}

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
Expand Down
35 changes: 28 additions & 7 deletions pkg/plugins/golang/v4/scaffolds/internal/templates/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/certwatcher"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
Expand All @@ -246,6 +247,7 @@ import (
var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
certWatcher *certwatcher.CertWatcher
)
func init() {
Expand Down Expand Up @@ -326,15 +328,25 @@ func main() {
// for the metrics server, suitable for development but not recommended for production.
// To use cert-manager-managed certificates, enable [METRICS WITH CERTMANAGER] in
// config/default/kustomization.yaml and specify CertDir, CertName, and KeyName accordingly.
if certDir != "" {
metricsServerOptions.CertDir = certDir
}
if certName != "" && certKey != "" {
metricsServerOptions.CertName = certName
metricsServerOptions.KeyName = certKey
setupLog.Info("using certName and certKey for the metrics server", "certName", certName, "certKey", certKey)
var err error
certWatcher, err = certwatcher.New(certName, certKey)
if err != nil {
setupLog.Error(err, "to initialize certificate watcher", "error", err)
os.Exit(1)
}
metricsServerOptions.TLSOpts = append(metricsServerOptions.TLSOpts, func(config *tls.Config) {
config.GetCertificate = certWatcher.GetCertificate
})
} else if certDir != "" {
setupLog.Info("using CertDir for the metrics server. ", "certDir", certDir)
metricsServerOptions.CertDir = certDir
} else {
setupLog.Info("Using self-signed certificates for the metrics server." +
"Consider informing the metrics server with your own certificates by setting CertDir or CertName and KeyName.")
}
}
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Expand Down Expand Up @@ -367,6 +379,15 @@ func main() {
%s
// Add Certificate Watcher to Manager
if certWatcher != nil {
setupLog.Info("Adding certificate watcher to manager")
if err := mgr.Add(certWatcher); err != nil {
setupLog.Error(err, "Failed to add certificate watcher to manager")
os.Exit(1)
}
}
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
Expand Down
39 changes: 30 additions & 9 deletions testdata/project-v4-multigroup/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/certwatcher"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
Expand Down Expand Up @@ -70,8 +71,9 @@ import (
)

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
certWatcher *certwatcher.CertWatcher
)

func init() {
Expand Down Expand Up @@ -165,15 +167,25 @@ func main() {
// for the metrics server, suitable for development but not recommended for production.
// To use cert-manager-managed certificates, enable [METRICS WITH CERTMANAGER] in
// config/default/kustomization.yaml and specify CertDir, CertName, and KeyName accordingly.
if certDir != "" {
metricsServerOptions.CertDir = certDir
}

if certName != "" && certKey != "" {
metricsServerOptions.CertName = certName
metricsServerOptions.KeyName = certKey
}
setupLog.Info("using certName and certKey for the metrics server", "certName", certName, "certKey", certKey)
var err error
certWatcher, err = certwatcher.New(certName, certKey)
if err != nil {
setupLog.Error(err, "to initialize certificate watcher", "error", err)
os.Exit(1)
}

metricsServerOptions.TLSOpts = append(metricsServerOptions.TLSOpts, func(config *tls.Config) {
config.GetCertificate = certWatcher.GetCertificate
})
} else if certDir != "" {
setupLog.Info("using CertDir for the metrics server. ", "certDir", certDir)
metricsServerOptions.CertDir = certDir
} else {
setupLog.Info("Using self-signed certificates for the metrics server." +
"Consider informing the metrics server with your own certificates by setting CertDir or CertName and KeyName.")
}
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Expand Down Expand Up @@ -358,6 +370,15 @@ func main() {
}
// +kubebuilder:scaffold:builder

// Add Certificate Watcher to Manager
if certWatcher != nil {
setupLog.Info("Adding certificate watcher to manager")
if err := mgr.Add(certWatcher); err != nil {
setupLog.Error(err, "Failed to add certificate watcher to manager")
os.Exit(1)
}
}

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
Expand Down
Loading

0 comments on commit 72ee944

Please sign in to comment.