Skip to content

Commit

Permalink
WMCO does not create and manage endpoints
Browse files Browse the repository at this point in the history
This commit removes the code responsible for
creating and managing metric endpoints object.
There is an endpoint named kubelet in the
kube-system namespace which contains all the
node IP addresses. WMCO can rely on this endpoint
and create the serviceMonitor which will change
the port from 10250 to 9182 which is our desired
metric port for the windows-exporter service
  • Loading branch information
mansikulkarni96 committed Oct 24, 2024
1 parent 7b76fb6 commit e5e261c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 442 deletions.
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
38 changes: 8 additions & 30 deletions controllers/windowsmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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/pkg/signer"
Expand Down Expand Up @@ -82,22 +81,15 @@ func NewWindowsMachineReconciler(mgr manager.Manager, clusterConfig cluster.Conf
return nil, fmt.Errorf("error creating machine client: %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)
}

return &WindowsMachineReconciler{
instanceReconciler: instanceReconciler{
client: mgr.GetClient(),
log: ctrl.Log.WithName("controller").WithName(WindowsMachineController),
k8sclientset: clientset,
clusterServiceCIDR: clusterConfig.Network().GetServiceCIDR(),
recorder: mgr.GetEventRecorderFor(WindowsMachineController),
watchNamespace: watchNamespace,
prometheusNodeConfig: pc,
platform: clusterConfig.Platform(),
client: mgr.GetClient(),
log: ctrl.Log.WithName("controller").WithName(WindowsMachineController),
k8sclientset: clientset,
clusterServiceCIDR: clusterConfig.Network().GetServiceCIDR(),
recorder: mgr.GetEventRecorderFor(WindowsMachineController),
watchNamespace: watchNamespace,
platform: clusterConfig.Platform(),
},
machineClient: machineClient,
}, nil
Expand Down Expand Up @@ -243,7 +235,7 @@ func (r *WindowsMachineReconciler) Reconcile(ctx context.Context,
// In the case the machine was deleted, ensure that the metrics subsets are configured properly, so that
// the current Windows nodes are properly reflected there.
log.V(1).Info("not found")
return ctrl.Result{}, r.prometheusNodeConfig.Configure()
return ctrl.Result{}, nil
}
// Error reading the object - requeue the request.
return ctrl.Result{}, err
Expand Down Expand Up @@ -299,21 +291,11 @@ func (r *WindowsMachineReconciler) Reconcile(ctx context.Context,
}
if node.Annotations[metadata.VersionAnnotation] == version.Get() {
// version annotation exists with a valid value, node is fully configured.
// configure Prometheus when we have already configured Windows Nodes. This is required to update
// Endpoints object if it gets reverted when the operator pod restarts.
if err := r.prometheusNodeConfig.Configure(); err != nil {
return ctrl.Result{}, fmt.Errorf("unable to configure Prometheus: %w", err)
}
return ctrl.Result{}, nil
}
}
} else if *machine.Status.Phase != provisionedPhase {
log.V(1).Info("machine not provisioned", "phase", *machine.Status.Phase)
// configure Prometheus when a machine is not in `Running` or `Provisioned` phase. This configuration is
// required to update Endpoints object when Windows machines are being deleted.
if err := r.prometheusNodeConfig.Configure(); err != nil {
return ctrl.Result{}, fmt.Errorf("unable to configure Prometheus: %w", err)
}
// Machine is not in provisioned or running state, nothing we should do as of now
return ctrl.Result{}, nil
}
Expand Down Expand Up @@ -360,10 +342,6 @@ func (r *WindowsMachineReconciler) Reconcile(ctx context.Context,
}
r.recorder.Eventf(machine, core.EventTypeNormal, "MachineSetup",
"Machine %s configured successfully", machine.Name)
// configure Prometheus after a Windows machine is configured as a Node.
if err := r.prometheusNodeConfig.Configure(); err != nil {
return ctrl.Result{}, fmt.Errorf("unable to configure Prometheus: %w", err)
}
return ctrl.Result{}, nil
}

Expand Down
Loading

0 comments on commit e5e261c

Please sign in to comment.