Skip to content

Commit

Permalink
Implement Upgrade-Monitor, FeatureGate, and MachineConfigNode types
Browse files Browse the repository at this point in the history
Signed-off-by: Charlie Doern <cdoern@redhat.com>
  • Loading branch information
cdoern committed Nov 16, 2023
1 parent f41e20d commit a1c792f
Show file tree
Hide file tree
Showing 145 changed files with 8,809 additions and 288 deletions.
43 changes: 29 additions & 14 deletions cmd/machine-config-controller/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/openshift/machine-config-operator/pkg/version"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/leaderelection"
"k8s.io/klog/v2"
)
Expand Down Expand Up @@ -63,31 +64,45 @@ func runStartCmd(_ *cobra.Command, _ []string) {
ctrlcommon.WriteTerminationError(fmt.Errorf("creating clients: %w", err))
}

ctrlctx := ctrlcommon.CreateControllerContext(runContext, cb)

// Start the shared factory informers that you need to use in your controller
ctrlctx.InformerFactory.Start(ctrlctx.Stop)
ctrlctx.KubeInformerFactory.Start(ctrlctx.Stop)
ctrlctx.OpenShiftConfigKubeNamespacedInformerFactory.Start(ctrlctx.Stop)
ctrlctx.OperatorInformerFactory.Start(ctrlctx.Stop)
ctrlctx.ConfigInformerFactory.Start(ctrlctx.Stop)

close(ctrlctx.InformersStarted)

select {
case <-ctrlctx.FeatureGateAccess.InitialFeatureGatesObserved():
featureGates, err := ctrlctx.FeatureGateAccess.CurrentFeatureGates()
if err != nil {
klog.Fatalf("Could not get FG: %w", err)
} else {
klog.Infof("FeatureGates initialized: knownFeatureGates=%v", featureGates.KnownFeatures())
}
case <-time.After(1 * time.Minute):
klog.Fatalf("Could not get FG, timed out: %w", err)
}

run := func(ctx context.Context) {
go common.SignalHandler(runCancel)

ctrlctx := ctrlcommon.CreateControllerContext(ctx, cb)

// Start the metrics handler
go ctrlcommon.StartMetricsListener(startOpts.promMetricsListenAddress, ctrlctx.Stop, ctrlcommon.RegisterMCCMetrics)

controllers := createControllers(ctrlctx)
kubeClient := ctrlctx.ClientBuilder.KubeClientOrDie("machine-config-controller")
controllers := createControllers(ctrlctx, kubeClient)
draincontroller := drain.New(
drain.DefaultConfig(),
ctrlctx.KubeInformerFactory.Core().V1().Nodes(),
ctrlctx.ClientBuilder.KubeClientOrDie("node-update-controller"),
ctrlctx.ClientBuilder.MachineConfigClientOrDie("node-update-controller"),
ctrlctx.FeatureGateAccess,
)

// Start the shared factory informers that you need to use in your controller
ctrlctx.InformerFactory.Start(ctrlctx.Stop)
ctrlctx.KubeInformerFactory.Start(ctrlctx.Stop)
ctrlctx.OpenShiftConfigKubeNamespacedInformerFactory.Start(ctrlctx.Stop)
ctrlctx.ConfigInformerFactory.Start(ctrlctx.Stop)
ctrlctx.OperatorInformerFactory.Start(ctrlctx.Stop)

close(ctrlctx.InformersStarted)

select {
case <-ctrlctx.FeatureGateAccess.InitialFeatureGatesObserved():
features, err := ctrlctx.FeatureGateAccess.CurrentFeatureGates()
Expand Down Expand Up @@ -130,9 +145,9 @@ func runStartCmd(_ *cobra.Command, _ []string) {
panic("unreachable")
}

func createControllers(ctx *ctrlcommon.ControllerContext) []ctrlcommon.Controller {
var controllers []ctrlcommon.Controller
func createControllers(ctx *ctrlcommon.ControllerContext, kubeClient kubernetes.Interface) []ctrlcommon.Controller {

var controllers []ctrlcommon.Controller
controllers = append(controllers,
// Our primary MCs come from here
template.New(
Expand Down
25 changes: 21 additions & 4 deletions cmd/machine-config-daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"net/url"
"os"
"time"

"k8s.io/client-go/tools/clientcmd"

Expand Down Expand Up @@ -166,25 +167,41 @@ func runStartCmd(_ *cobra.Command, _ []string) {
go ctrlcommon.StartMetricsListener(startOpts.promMetricsURL, stopCh, daemon.RegisterMCDMetrics)

ctrlctx := ctrlcommon.CreateControllerContext(ctx, cb)

ctrlctx.ConfigInformerFactory.Start(ctrlctx.Stop)
ctrlctx.KubeInformerFactory.Start(stopCh)
ctrlctx.InformerFactory.Start(stopCh)
close(ctrlctx.InformersStarted)

select {
case <-ctrlctx.FeatureGateAccess.InitialFeatureGatesObserved():
featureGates, err := ctrlctx.FeatureGateAccess.CurrentFeatureGates()
if err != nil {
klog.Fatalf("Could not get FG: %w", err)
} else {
klog.Infof("FeatureGates initialized: knownFeatureGates=%v", featureGates.KnownFeatures())
}
case <-time.After(1 * time.Minute):
klog.Fatalf("Could not get FG, timed out: %w", err)
}

// create the daemon instance. this also initializes kube client items
// which need to come from the container and not the chroot.
err = dn.ClusterConnect(
startOpts.nodeName,
kubeClient,
ctrlctx.ClientBuilder.MachineConfigClientOrDie(componentName),
ctrlctx.InformerFactory.Machineconfiguration().V1().MachineConfigs(),
ctrlctx.KubeInformerFactory.Core().V1().Nodes(),
ctrlctx.InformerFactory.Machineconfiguration().V1().ControllerConfigs(),
startOpts.kubeletHealthzEnabled,
startOpts.kubeletHealthzEndpoint,
ctrlctx.FeatureGateAccess,
)
if err != nil {
klog.Fatalf("Failed to initialize: %v", err)
}

ctrlctx.KubeInformerFactory.Start(stopCh)
ctrlctx.InformerFactory.Start(stopCh)
close(ctrlctx.InformersStarted)

if err := dn.Run(stopCh, exitCh); err != nil {
ctrlcommon.WriteTerminationError(err)
}
Expand Down
44 changes: 30 additions & 14 deletions cmd/machine-config-operator/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"flag"
"os"
"time"

"github.com/openshift/machine-config-operator/cmd/common"
"github.com/openshift/machine-config-operator/internal/clients"
Expand Down Expand Up @@ -60,13 +61,36 @@ func runStartCmd(_ *cobra.Command, _ []string) {
stopCh := make(chan struct{})
defer close(stopCh)

// start metrics listener
go ctrlcommon.StartMetricsListener(startOpts.promMetricsURL, stopCh, operator.RegisterMCOMetrics)
ctrlctx := ctrlcommon.CreateControllerContext(runContext, cb)
ctrlctx.ConfigInformerFactory.Start(ctrlctx.Stop)
ctrlctx.NamespacedInformerFactory.Start(ctrlctx.Stop)
ctrlctx.KubeInformerFactory.Start(ctrlctx.Stop)
ctrlctx.KubeNamespacedInformerFactory.Start(ctrlctx.Stop)
ctrlctx.APIExtInformerFactory.Start(ctrlctx.Stop)
ctrlctx.OpenShiftKubeAPIServerKubeNamespacedInformerFactory.Start(ctrlctx.Stop)
ctrlctx.OpenShiftConfigKubeNamespacedInformerFactory.Start(ctrlctx.Stop)
ctrlctx.OperatorInformerFactory.Start(ctrlctx.Stop)
ctrlctx.KubeMAOSharedInformer.Start(ctrlctx.Stop)
close(ctrlctx.InformersStarted)

select {
case <-ctrlctx.FeatureGateAccess.InitialFeatureGatesObserved():
featureGates, err := ctrlctx.FeatureGateAccess.CurrentFeatureGates()
if err != nil {
klog.Fatalf("Could not get FG: %w", err)
} else {
klog.Infof("FeatureGates initialized: knownFeatureGates=%v", featureGates.KnownFeatures())
}
case <-time.After(1 * time.Minute):
klog.Fatalf("Could not get FG, timed out: %w", err)
}

run := func(ctx context.Context) {
go common.SignalHandler(runCancel)

ctrlctx := ctrlcommon.CreateControllerContext(ctx, cb)
// start metrics listener
go ctrlcommon.StartMetricsListener(startOpts.promMetricsURL, stopCh, operator.RegisterMCOMetrics)

controller := operator.New(
ctrlcommon.MCONamespace, componentName,
startOpts.imagesFile,
Expand All @@ -89,6 +113,7 @@ func runStartCmd(_ *cobra.Command, _ []string) {
ctrlctx.ClientBuilder.KubeClientOrDie(componentName),
ctrlctx.ClientBuilder.APIExtClientOrDie(componentName),
ctrlctx.ClientBuilder.ConfigClientOrDie(componentName),
ctrlctx.ClientBuilder.OperatorClientOrDie(componentName),
ctrlctx.OpenShiftKubeAPIServerKubeNamespacedInformerFactory.Core().V1().ConfigMaps(),
ctrlctx.KubeInformerFactory.Core().V1().Nodes(),
ctrlctx.KubeMAOSharedInformer.Core().V1().Secrets(),
Expand All @@ -97,19 +122,10 @@ func runStartCmd(_ *cobra.Command, _ []string) {
ctrlctx.KubeNamespacedInformerFactory.Core().V1().Secrets(),
ctrlctx.OpenShiftConfigKubeNamespacedInformerFactory.Core().V1().Secrets(),
ctrlctx.ConfigInformerFactory.Config().V1().ClusterOperators(),
ctrlctx.NamespacedInformerFactory.Machineconfiguration().V1alpha1().MachineConfigNodes(),
ctrlctx.FeatureGateAccess,
)

ctrlctx.NamespacedInformerFactory.Start(ctrlctx.Stop)
ctrlctx.KubeInformerFactory.Start(ctrlctx.Stop)
ctrlctx.KubeNamespacedInformerFactory.Start(ctrlctx.Stop)
ctrlctx.APIExtInformerFactory.Start(ctrlctx.Stop)
ctrlctx.ConfigInformerFactory.Start(ctrlctx.Stop)
ctrlctx.OpenShiftKubeAPIServerKubeNamespacedInformerFactory.Start(ctrlctx.Stop)
ctrlctx.OpenShiftConfigKubeNamespacedInformerFactory.Start(ctrlctx.Stop)
ctrlctx.OperatorInformerFactory.Start(ctrlctx.Stop)
ctrlctx.KubeMAOSharedInformer.Start(ctrlctx.Stop)
close(ctrlctx.InformersStarted)

go controller.Run(2, ctrlctx.Stop)

// wait here in this function until the context gets cancelled (which tells us whe were being shut down)
Expand Down
4 changes: 2 additions & 2 deletions docs/ContainerRuntimeConfigDesign.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ e.g.

```bash
$ oc logs -f -n openshift-machine-config-operator machine-config-controller-6fc64d9654-mdtv4
W0330 08:03:49.665463 1 reflector.go:436] github.com/openshift/machine-config-operator/pkg/generated/informers/externalversions/factory.go:101: watch of *v1.ContainerRuntimeConfig ended with: an error on the server ("unable to decode an event from the watch stream: unable to decode watch event: v1.ContainerRuntimeConfig.Spec: v1.ContainerRuntimeConfigSpec.MachineConfigPoolSelector: ContainerRuntimeConfig: v1.ContainerRuntimeConfiguration.OverlaySize: unmarshalerDecoder: quantities must match the regular expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$', error found in #10 byte of ...|\":\"9asadG\"},\"machine|..., bigger context ...|:{\"containerRuntimeConfig\":{\"overlaySize\":\"9asadG\"},\"machineConfigPoolSelector\":{\"matchLabels\":{\"cus|...") has prevented the request from succeeding
E0330 08:03:50.810155 1 reflector.go:138] github.com/openshift/machine-config-operator/pkg/generated/informers/externalversions/factory.go:101: Failed to watch *v1.ContainerRuntimeConfig: failed to list *v1.ContainerRuntimeConfig: v1.ContainerRuntimeConfigList.Items: []v1.ContainerRuntimeConfig: v1.ContainerRuntimeConfig.Spec: v1.ContainerRuntimeConfigSpec.MachineConfigPoolSelector: ContainerRuntimeConfig: v1.ContainerRuntimeConfiguration.OverlaySize: unmarshalerDecoder: quantities must match the regular expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$', error found in #10 byte of ...|":"9asadG"},"machine|..., bigger context ...|:{"containerRuntimeConfig":{"overlaySize":"9asadG"},"machineConfigPoolSelector":{"matchLabels":{"cus|...
W0330 08:03:49.665463 1 reflector.go:436] github.com/openshift/client-go/machineconfiguration/informers/externalversions/factory.go:101: watch of *v1.ContainerRuntimeConfig ended with: an error on the server ("unable to decode an event from the watch stream: unable to decode watch event: v1.ContainerRuntimeConfig.Spec: v1.ContainerRuntimeConfigSpec.MachineConfigPoolSelector: ContainerRuntimeConfig: v1.ContainerRuntimeConfiguration.OverlaySize: unmarshalerDecoder: quantities must match the regular expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$', error found in #10 byte of ...|\":\"9asadG\"},\"machine|..., bigger context ...|:{\"containerRuntimeConfig\":{\"overlaySize\":\"9asadG\"},\"machineConfigPoolSelector\":{\"matchLabels\":{\"cus|...") has prevented the request from succeeding
E0330 08:03:50.810155 1 reflector.go:138] github.com/openshift/client-go/machineconfiguration/informers/externalversions/factory.go:101: Failed to watch *v1.ContainerRuntimeConfig: failed to list *v1.ContainerRuntimeConfig: v1.ContainerRuntimeConfigList.Items: []v1.ContainerRuntimeConfig: v1.ContainerRuntimeConfig.Spec: v1.ContainerRuntimeConfigSpec.MachineConfigPoolSelector: ContainerRuntimeConfig: v1.ContainerRuntimeConfiguration.OverlaySize: unmarshalerDecoder: quantities must match the regular expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$', error found in #10 byte of ...|":"9asadG"},"machine|..., bigger context ...|:{"containerRuntimeConfig":{"overlaySize":"9asadG"},"machineConfigPoolSelector":{"matchLabels":{"cus|...
```

## Example
Expand Down
Loading

0 comments on commit a1c792f

Please sign in to comment.