Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WINC-545: Improve handling of metrics configuration #2485

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,6 @@ spec:
- get
- patch
- update
- apiGroups:
- ""
resources:
- endpoints
verbs:
- create
- delete
- get
- patch
- update
- apiGroups:
- ""
resources:
Expand All @@ -211,6 +201,8 @@ spec:
- namespaces
verbs:
- get
- list
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please squash this into the commit the kubebuilder directives are being added.
Else this will cause revert issues if one of the commits needs to be reverted

- watch
- apiGroups:
- ""
resources:
Expand Down
19 changes: 8 additions & 11 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

"github.com/openshift/windows-machine-config-operator/controllers"
"github.com/openshift/windows-machine-config-operator/pkg/cluster"
"github.com/openshift/windows-machine-config-operator/pkg/metrics"
"github.com/openshift/windows-machine-config-operator/pkg/nodeconfig/payload"
"github.com/openshift/windows-machine-config-operator/pkg/servicescm"
"github.com/openshift/windows-machine-config-operator/pkg/windows"
Expand Down Expand Up @@ -266,22 +265,20 @@ func main() {
os.Exit(1)
}

//+kubebuilder:scaffold:builder
// The above marker tells kubebuilder that this is where the SetupWithManager function should be inserted when new
// controllers are generated by Operator SDK.

metricsConfig, err := metrics.NewConfig(mgr, cfg, watchNamespace)
mReconciler, err := controllers.NewMetricReconciler(mgr, clusterConfig, cfg, watchNamespace)
if err != nil {
setupLog.Error(err, "failed to create MetricsConfig object")
setupLog.Error(err, "unable to create metrics reconciler")
os.Exit(1)
}

// Configure the metric resources
if err := metricsConfig.Configure(ctx); err != nil {
setupLog.Error(err, "error setting up metrics")
if err = mReconciler.SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Metrics")
os.Exit(1)
}

//+kubebuilder:scaffold:builder
// The above marker tells kubebuilder that this is where the SetupWithManager function should be inserted when new
// controllers are generated by Operator SDK.

// Create the singleton Windows services ConfigMap
if err := configMapReconciler.EnsureServicesConfigMapExists(); err != nil {
setupLog.Error(err, "error ensuring object exists", "singleton", types.NamespacedName{Namespace: watchNamespace,
Expand Down
12 changes: 2 additions & 10 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ rules:
- get
- patch
- update
- apiGroups:
- ""
resources:
- endpoints
verbs:
- create
- delete
- get
- patch
- update
- apiGroups:
- ""
resources:
Expand All @@ -53,6 +43,8 @@ rules:
- namespaces
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
Expand Down
26 changes: 7 additions & 19 deletions controllers/configmap_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import (
"github.com/openshift/windows-machine-config-operator/pkg/crypto"
"github.com/openshift/windows-machine-config-operator/pkg/ignition"
"github.com/openshift/windows-machine-config-operator/pkg/instance"
"github.com/openshift/windows-machine-config-operator/pkg/metrics"
"github.com/openshift/windows-machine-config-operator/pkg/nodeconfig"
"github.com/openshift/windows-machine-config-operator/pkg/patch"
"github.com/openshift/windows-machine-config-operator/pkg/secrets"
Expand Down Expand Up @@ -93,12 +92,6 @@ func NewConfigMapReconciler(mgr manager.Manager, clusterConfig cluster.Config, w
return nil, fmt.Errorf("error creating kubernetes clientset: %w", err)
}

// Initialize prometheus configuration
pc, err := metrics.NewPrometheusNodeConfig(clientset, watchNamespace)
if err != nil {
return nil, fmt.Errorf("unable to initialize Prometheus configuration: %w", err)
}

directClient, err := client.New(mgr.GetConfig(), client.Options{Scheme: mgr.GetScheme()})
if err != nil {
return nil, err
Expand All @@ -119,14 +112,13 @@ func NewConfigMapReconciler(mgr manager.Manager, clusterConfig cluster.Config, w

return &ConfigMapReconciler{
instanceReconciler: instanceReconciler{
client: mgr.GetClient(),
k8sclientset: clientset,
clusterServiceCIDR: clusterConfig.Network().GetServiceCIDR(),
log: ctrl.Log.WithName("controllers").WithName(ConfigMapController),
watchNamespace: watchNamespace,
recorder: mgr.GetEventRecorderFor(ConfigMapController),
prometheusNodeConfig: pc,
platform: clusterConfig.Platform(),
client: mgr.GetClient(),
k8sclientset: clientset,
clusterServiceCIDR: clusterConfig.Network().GetServiceCIDR(),
log: ctrl.Log.WithName("controllers").WithName(ConfigMapController),
watchNamespace: watchNamespace,
recorder: mgr.GetEventRecorderFor(ConfigMapController),
platform: clusterConfig.Platform(),
},
servicesManifest: svcData,
proxyEnabled: proxyEnabled,
Expand Down Expand Up @@ -288,10 +280,6 @@ func (r *ConfigMapReconciler) reconcileNodes(ctx context.Context, windowsInstanc
return fmt.Errorf("error removing undesired nodes from cluster: %w", err)
}

// Once all the proper Nodes are in the cluster, configure the prometheus endpoints.
if err := r.prometheusNodeConfig.Configure(); err != nil {
return fmt.Errorf("unable to configure Prometheus: %w", err)
}
return nil
}

Expand Down
3 changes: 0 additions & 3 deletions controllers/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/openshift/windows-machine-config-operator/pkg/crypto"
"github.com/openshift/windows-machine-config-operator/pkg/instance"
"github.com/openshift/windows-machine-config-operator/pkg/metadata"
"github.com/openshift/windows-machine-config-operator/pkg/metrics"
"github.com/openshift/windows-machine-config-operator/pkg/nodeconfig"
"github.com/openshift/windows-machine-config-operator/pkg/secrets"
"github.com/openshift/windows-machine-config-operator/version"
Expand Down Expand Up @@ -51,8 +50,6 @@ type instanceReconciler struct {
watchNamespace string
// signer is a signer created from the user's private key
signer ssh.Signer
// prometheusNodeConfig stores information required to configure Prometheus
prometheusNodeConfig *metrics.PrometheusNodeConfig
// recorder to generate events
recorder record.EventRecorder
// platform indicates the cloud on which the cluster is running
Expand Down
Loading