Skip to content

Commit

Permalink
Upgrade addon-manager and k8s libs
Browse files Browse the repository at this point in the history
Signed-off-by: Douglas Camata <[email protected]>
  • Loading branch information
douglascamata committed Jun 5, 2024
1 parent 375b31f commit 7568e34
Show file tree
Hide file tree
Showing 8 changed files with 2,154 additions and 537 deletions.
240 changes: 127 additions & 113 deletions go.mod

Large diffs are not rendered by default.

2,331 changes: 1,964 additions & 367 deletions go.sum

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions operators/endpointmetrics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
ctrlwebhook "sigs.k8s.io/controller-runtime/pkg/webhook"

obsepctl "github.com/stolostron/multicluster-observability-operator/operators/endpointmetrics/controllers/observabilityendpoint"
statusctl "github.com/stolostron/multicluster-observability-operator/operators/endpointmetrics/controllers/status"
Expand Down Expand Up @@ -110,12 +112,12 @@ func main() {

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
Metrics: server.Options{BindAddress: metricsAddr},
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "7c30ca38.open-cluster-management.io",
NewCache: filteredcache.NewEnhancedFilteredCacheBuilder(gvkLabelMap),
WebhookServer: ctrlwebhook.NewServer(ctrlwebhook.Options{Port: 9443}),
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down Expand Up @@ -158,7 +160,7 @@ func main() {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
}
if err := operatorsutil.RegisterDebugEndpoint(mgr.AddMetricsExtraHandler); err != nil {
if err := operatorsutil.RegisterDebugEndpoint(mgr.AddMetricsServerExtraHandler); err != nil {
setupLog.Error(err, "unable to set up debug handler")
os.Exit(1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// +kubebuilder:docs-gen:collapse=Go imports
Expand All @@ -36,23 +37,23 @@ func (mco *MultiClusterObservability) SetupWebhookWithManager(mgr ctrl.Manager)
var _ webhook.Validator = &MultiClusterObservability{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (mco *MultiClusterObservability) ValidateCreate() error {
func (mco *MultiClusterObservability) ValidateCreate() (admission.Warnings, error) {
multiclusterobservabilitylog.Info("validate create", "name", mco.Name)
return mco.validateMultiClusterObservability(nil)
return nil, mco.validateMultiClusterObservability(nil)
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (mco *MultiClusterObservability) ValidateUpdate(old runtime.Object) error {
func (mco *MultiClusterObservability) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
multiclusterobservabilitylog.Info("validate update", "name", mco.Name)
return mco.validateMultiClusterObservability(old)
return nil, mco.validateMultiClusterObservability(old)
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (mco *MultiClusterObservability) ValidateDelete() error {
func (mco *MultiClusterObservability) ValidateDelete() (admission.Warnings, error) {
multiclusterobservabilitylog.Info("validate delete", "name", mco.Name)

// no validation logic upon object delete.
return nil
return nil, nil
}

// validateMultiClusterObservability validates the name and the spec of the MultiClusterObservability CR.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (

"github.com/go-logr/logr"
routev1 "github.com/openshift/api/route/v1"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
mchv1 "github.com/stolostron/multiclusterhub-operator/api/v1"
observatoriumv1alpha1 "github.com/stolostron/observatorium-operator/api/v1alpha1"
"golang.org/x/exp/slices"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -39,11 +42,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
mchv1 "github.com/stolostron/multiclusterhub-operator/api/v1"
observatoriumv1alpha1 "github.com/stolostron/observatorium-operator/api/v1alpha1"

mcov1beta2 "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/api/v1beta2"
placementctrl "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/controllers/placementrule"
Expand Down Expand Up @@ -461,15 +459,15 @@ func (r *MultiClusterObservabilityReconciler) SetupWithManager(mgr ctrl.Manager)
// Watch for changes to secondary Observatorium CR and requeue the owner MultiClusterObservability
Owns(&observatoriumv1alpha1.Observatorium{}).
// Watch the configmap for thanos-ruler-custom-rules update
Watches(&source.Kind{Type: &corev1.ConfigMap{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(cmPred)).
Watches(&corev1.ConfigMap{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(cmPred)).
// Watch the secret for deleting event of alertmanager-config
Watches(&source.Kind{Type: &corev1.Secret{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(secretPred)).
Watches(&corev1.Secret{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(secretPred)).
// Watch the namespace for changes
Watches(&source.Kind{Type: &corev1.Namespace{}}, &handler.EnqueueRequestForObject{},
Watches(&corev1.Namespace{}, &handler.EnqueueRequestForObject{},
builder.WithPredicates(namespacePred)).
// Watch the kube-system extension-apiserver-authentication ConfigMap for changes
Watches(&source.Kind{Type: &corev1.ConfigMap{}}, handler.EnqueueRequestsFromMapFunc(
func(a client.Object) []reconcile.Request {
Watches(&corev1.ConfigMap{}, handler.EnqueueRequestsFromMapFunc(
func(ctx context.Context, a client.Object) []reconcile.Request {
if a.GetName() == "extension-apiserver-authentication" && a.GetNamespace() == "kube-system" {
return []reconcile.Request{
{NamespacedName: types.NamespacedName{
Expand All @@ -488,8 +486,8 @@ func (r *MultiClusterObservabilityReconciler) SetupWithManager(mgr ctrl.Manager)
if mchCrdExists {
// secondary watch for MCH
ctrBuilder = ctrBuilder.Watches(
&source.Kind{Type: &mchv1.MultiClusterHub{}},
handler.EnqueueRequestsFromMapFunc(func(a client.Object) []reconcile.Request {
&mchv1.MultiClusterHub{},
handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, a client.Object) []reconcile.Request {
return []reconcile.Request{
{NamespacedName: types.NamespacedName{
Name: config.MCHUpdatedRequestName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -980,9 +980,9 @@ func newVolumeClaimTemplate(size string, storageClass string) obsv1alpha1.Volume
vct.Spec = v1.PersistentVolumeClaimSpec{
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce},
StorageClassName: &storageClass,
Resources: v1.ResourceRequirements{
Resources: v1.VolumeResourceRequirements{
Requests: v1.ResourceList{
v1.ResourceName(v1.ResourceStorage): resource.MustParse(size),
v1.ResourceStorage: resource.MustParse(size),
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/go-logr/logr"
operatorv1 "github.com/openshift/api/operator/v1"
mchv1 "github.com/stolostron/multiclusterhub-operator/api/v1"
"golang.org/x/exp/slices"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -25,6 +26,9 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
addonv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
clusterv1 "open-cluster-management.io/api/cluster/v1"
workv1 "open-cluster-management.io/api/work/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -34,12 +38,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

mchv1 "github.com/stolostron/multiclusterhub-operator/api/v1"
addonv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
clusterv1 "open-cluster-management.io/api/cluster/v1"
workv1 "open-cluster-management.io/api/work/v1"

mcov1beta1 "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/api/v1beta1"
mcov1beta2 "github.com/stolostron/multicluster-observability-operator/operators/multiclusterobservability/api/v1beta2"
Expand Down Expand Up @@ -896,10 +894,10 @@ func (r *PlacementRuleReconciler) SetupWithManager(mgr ctrl.Manager) error {
// Watch for changes to primary resource ManagedCluster with predicate
For(&clusterv1.ManagedCluster{}, builder.WithPredicates(clusterPred)).
// secondary watch for observabilityaddon
Watches(&source.Kind{Type: &mcov1beta1.ObservabilityAddon{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(obsAddonPred)).
Watches(&mcov1beta1.ObservabilityAddon{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(obsAddonPred)).

// secondary watch for MCO
Watches(&source.Kind{Type: &mcov1beta2.MultiClusterObservability{}}, handler.EnqueueRequestsFromMapFunc(func(obj client.Object) []reconcile.Request {
Watches(&mcov1beta2.MultiClusterObservability{}, handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, obj client.Object) []reconcile.Request {
return []reconcile.Request{
{NamespacedName: types.NamespacedName{
Name: config.MCOUpdatedRequestName,
Expand All @@ -908,20 +906,20 @@ func (r *PlacementRuleReconciler) SetupWithManager(mgr ctrl.Manager) error {
}), builder.WithPredicates(getMCOPred(c, ingressCtlCrdExists))).

// secondary watch for custom allowlist configmap
Watches(&source.Kind{Type: &corev1.ConfigMap{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(allowlistPred)).
Watches(&corev1.ConfigMap{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(allowlistPred)).

// secondary watch for certificate secrets
Watches(&source.Kind{Type: &corev1.Secret{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(certSecretPred)).
Watches(&corev1.Secret{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(certSecretPred)).

// secondary watch for alertmanager accessor serviceaccount
Watches(&source.Kind{Type: &corev1.ServiceAccount{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(amAccessorSAPred))
Watches(&corev1.ServiceAccount{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(amAccessorSAPred))

// watch for AddOnDeploymentConfig
addOnDeploymentConfigGroupKind := schema.GroupKind{Group: addonv1alpha1.GroupVersion.Group, Kind: "AddOnDeploymentConfig"}
if _, err := r.RESTMapper.RESTMapping(addOnDeploymentConfigGroupKind, addonv1alpha1.GroupVersion.Version); err == nil {
ctrBuilder = ctrBuilder.Watches(
&source.Kind{Type: &addonv1alpha1.AddOnDeploymentConfig{}},
handler.EnqueueRequestsFromMapFunc(func(obj client.Object) []reconcile.Request {
&addonv1alpha1.AddOnDeploymentConfig{},
handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, obj client.Object) []reconcile.Request {
return []reconcile.Request{
{NamespacedName: types.NamespacedName{
Name: config.AddonDeploymentConfigUpdateName,
Expand All @@ -936,7 +934,7 @@ func (r *PlacementRuleReconciler) SetupWithManager(mgr ctrl.Manager) error {
workPred := getManifestworkPred()
// secondary watch for manifestwork
ctrBuilder = ctrBuilder.Watches(
&source.Kind{Type: &workv1.ManifestWork{}},
&workv1.ManifestWork{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(workPred),
)
Expand All @@ -948,8 +946,8 @@ func (r *PlacementRuleReconciler) SetupWithManager(mgr ctrl.Manager) error {

// secondary watch for clustermanagementaddon
ctrBuilder = ctrBuilder.Watches(
&source.Kind{Type: &addonv1alpha1.ClusterManagementAddOn{}},
handler.EnqueueRequestsFromMapFunc(func(obj client.Object) []reconcile.Request {
&addonv1alpha1.ClusterManagementAddOn{},
handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, obj client.Object) []reconcile.Request {
return []reconcile.Request{
{NamespacedName: types.NamespacedName{
Name: config.ClusterManagementAddOnUpdateName,
Expand All @@ -966,7 +964,7 @@ func (r *PlacementRuleReconciler) SetupWithManager(mgr ctrl.Manager) error {

// secondary watch for managedclusteraddon
ctrBuilder = ctrBuilder.Watches(
&source.Kind{Type: &addonv1alpha1.ManagedClusterAddOn{}},
&addonv1alpha1.ManagedClusterAddOn{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(mgClusterGroupKindPred),
)
Expand All @@ -978,21 +976,21 @@ func (r *PlacementRuleReconciler) SetupWithManager(mgr ctrl.Manager) error {

if ingressCtlCrdExists {
// secondary watch for default ingresscontroller
ctrBuilder = ctrBuilder.Watches(&source.Kind{Type: &operatorv1.IngressController{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(ingressControllerPred)).
ctrBuilder = ctrBuilder.Watches(&operatorv1.IngressController{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(ingressControllerPred)).

// secondary watch for alertmanager route byo cert secrets
Watches(&source.Kind{Type: &corev1.Secret{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(amRouterCertSecretPred)).
Watches(&corev1.Secret{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(amRouterCertSecretPred)).

// secondary watch for openshift route ca secret
Watches(&source.Kind{Type: &corev1.Secret{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(routeCASecretPred))
Watches(&corev1.Secret{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(routeCASecretPred))
}

mchCrdExists := r.CRDMap[config.MCHCrdName]
if mchCrdExists {
// secondary watch for MCH
ctrBuilder = ctrBuilder.Watches(
&source.Kind{Type: &mchv1.MultiClusterHub{}},
handler.EnqueueRequestsFromMapFunc(func(obj client.Object) []reconcile.Request {
&mchv1.MultiClusterHub{},
handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, obj client.Object) []reconcile.Request {
return []reconcile.Request{
{NamespacedName: types.NamespacedName{
Name: config.MCHUpdatedRequestName,
Expand All @@ -1008,39 +1006,39 @@ func (r *PlacementRuleReconciler) SetupWithManager(mgr ctrl.Manager) error {
// ACM 8509: Special case for hub/local cluster metrics collection
// secondary watch for hub endpoint operator deployment

ctrBuilder = ctrBuilder.Watches(&source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(hubEndpointOperatorPred)).
ctrBuilder = ctrBuilder.Watches(&appsv1.Deployment{}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(hubEndpointOperatorPred)).
Watches(
&source.Kind{Type: &corev1.Secret{}},
&corev1.Secret{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(getPred(operatorconfig.HubInfoSecretName, config.GetDefaultNamespace(), false, false, true)),
).
Watches(
&source.Kind{Type: &corev1.Secret{}},
&corev1.Secret{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(getPred(operatorconfig.HubMetricsCollectorMtlsCert, config.GetDefaultNamespace(), false, false, true)),
).
Watches(
&source.Kind{Type: &corev1.Secret{}},
&corev1.Secret{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(getPred(managedClusterObsCertName, config.GetDefaultNamespace(), false, false, true)),
).
Watches(
&source.Kind{Type: &corev1.ConfigMap{}},
&corev1.ConfigMap{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(getPred(operatorconfig.ImageConfigMap, config.GetDefaultNamespace(), false, false, true)),
).
Watches(
&source.Kind{Type: &appsv1.StatefulSet{}},
&appsv1.StatefulSet{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(getPred(operatorconfig.PrometheusUserWorkload, config.HubUwlMetricsCollectorNs, true, false, true)),
).
Watches(
&source.Kind{Type: &corev1.Secret{}},
&corev1.Secret{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(getPred(config.AlertmanagerAccessorSecretName, config.GetDefaultNamespace(), false, false, true)),
).
Watches(
&source.Kind{Type: &corev1.ServiceAccount{}},
&corev1.ServiceAccount{},
&handler.EnqueueRequestForObject{},
builder.WithPredicates(getPred(config.HubEndpointSaName, config.GetDefaultNamespace(), false, false, true)),
)
Expand Down
15 changes: 11 additions & 4 deletions operators/multiclusterobservability/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package main

import (
"crypto/tls"
"flag"
"fmt"
"os"
Expand All @@ -14,6 +15,7 @@ import (

"go.uber.org/zap/zapcore"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"

"github.com/IBM/controller-filtered-cache/filteredcache"
ocinfrav1 "github.com/openshift/api/config/v1"
Expand Down Expand Up @@ -232,14 +234,19 @@ func main() {
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Port: webhookPort,
Scheme: scheme,
MetricsBindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort),
Metrics: server.Options{BindAddress: fmt.Sprintf("%s:%d", metricsHost, metricsPort)},
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "b9d51391.open-cluster-management.io",
NewCache: filteredcache.NewEnhancedFilteredCacheBuilder(gvkLabelsMap),
WebhookServer: &ctrlwebhook.Server{TLSMinVersion: "1.2"},
WebhookServer: ctrlwebhook.NewServer(ctrlwebhook.Options{
Port: webhookPort,
TLSOpts: []func(*tls.Config){
func(t *tls.Config) {
t.MinVersion = tls.VersionTLS12
},
}}),
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down Expand Up @@ -296,7 +303,7 @@ func main() {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
}
if err := operatorsutil.RegisterDebugEndpoint(mgr.AddMetricsExtraHandler); err != nil {
if err := operatorsutil.RegisterDebugEndpoint(mgr.AddMetricsServerExtraHandler); err != nil {
setupLog.Error(err, "unable to set up debug handler")
os.Exit(1)
}
Expand Down

0 comments on commit 7568e34

Please sign in to comment.