Skip to content
Merged
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
3 changes: 1 addition & 2 deletions cmd/machine-config-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
)

const (
componentName = "machine-config-controller"
componentNamespace = "openshift-machine-config-operator"
componentName = "machine-config-controller"
)

var (
Expand Down
1 change: 0 additions & 1 deletion cmd/machine-config-controller/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ func createControllers(ctx *ctrlcommon.ControllerContext) []ctrlcommon.Controlle
),
containerruntimeconfig.New(
rootOpts.templates,
componentNamespace,
ctx.InformerFactory.Machineconfiguration().V1().MachineConfigPools(),
ctx.InformerFactory.Machineconfiguration().V1().ControllerConfigs(),
ctx.InformerFactory.Machineconfiguration().V1().ContainerRuntimeConfigs(),
Expand Down
6 changes: 0 additions & 6 deletions pkg/controller/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,6 @@ func (b *Bootstrap) Run(destDir string) error {

configs = append(configs, rconfigs...)

defaultRuntimeUseconfigs, err := containerruntimeconfig.RunDefaultContainerRuntimeBootstrap(pools)
if err != nil {
return err
}
configs = append(configs, defaultRuntimeUseconfigs...)

if len(crconfigs) > 0 {
containerRuntimeConfigs, err := containerruntimeconfig.RunContainerRuntimeBootstrap(b.templatesDir, crconfigs, cconfig, pools)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ func TestAddKubeletCfgAfterBootstrapKubeletCfg(t *testing.T) {
helpers.NewMachineConfigPool("master", nil, helpers.MasterSelector, "v0"),
}
// ctrcfg for bootstrap mode
cm := newConfigMap("crio-default-container-runtime")
ctrcfg := newContainerRuntimeConfig("log-level", &mcfgv1.ContainerRuntimeConfiguration{LogLevel: "debug"}, metav1.AddLabelToSelector(&metav1.LabelSelector{}, "pools.operator.machineconfiguration.openshift.io/master", ""))

f.ccLister = append(f.ccLister, cc)
f.mcpLister = append(f.mcpLister, pools[0])
f.mccrLister = append(f.mccrLister, ctrcfg)
f.objects = append(f.objects, ctrcfg)
f.k8sObjects = append(f.k8sObjects, cm)

mcs, err := RunContainerRuntimeBootstrap("../../../templates", []*mcfgv1.ContainerRuntimeConfig{ctrcfg}, cc, pools)
require.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
operatorlistersv1alpha1 "github.com/openshift/client-go/operator/listers/operator/v1alpha1"
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -62,9 +61,7 @@ const (
// 5ms, 10ms, 20ms, 40ms, 80ms, 160ms, 320ms, 640ms, 1.3s, 2.6s, 5.1s, 10.2s, 20.4s, 41s, 82s
maxRetries = 15

builtInLabelKey = "machineconfiguration.openshift.io/mco-built-in"
configMapName = "crio-default-container-runtime"
forceSyncOnUpgrade = "force-sync-on-upgrade"
builtInLabelKey = "machineconfiguration.openshift.io/mco-built-in"
)

var (
Expand All @@ -81,11 +78,9 @@ var updateBackoff = wait.Backoff{
// Controller defines the container runtime config controller.
type Controller struct {
templatesDir string
namespace string

client mcfgclientset.Interface
configClient configclientset.Interface
kubeClient clientset.Interface
eventRecorder record.EventRecorder

syncHandler func(mcp string) error
Expand Down Expand Up @@ -129,7 +124,7 @@ type Controller struct {

// New returns a new container runtime config controller
func New(
templatesDir, namespace string,
templatesDir string,
mcpInformer mcfginformersv1.MachineConfigPoolInformer,
ccInformer mcfginformersv1.ControllerConfigInformer,
mcrInformer mcfginformersv1.ContainerRuntimeConfigInformer,
Expand All @@ -150,13 +145,11 @@ func New(

ctrl := &Controller{
templatesDir: templatesDir,
namespace: namespace,
client: mcfgClient,
configClient: configClient,
eventRecorder: ctrlcommon.NamespacedEventRecorder(eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: "machineconfigcontroller-containerruntimeconfigcontroller"})),
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "machineconfigcontroller-containerruntimeconfigcontroller"),
imgQueue: workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter()),
kubeClient: kubeClient,
}

mcrInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
Expand Down Expand Up @@ -216,7 +209,6 @@ func New(

ctrl.clusterVersionLister = clusterVersionInformer.Lister()
ctrl.clusterVersionListerSynced = clusterVersionInformer.Informer().HasSynced
ctrl.queue.Add(forceSyncOnUpgrade)

ctrl.featureGateAccess = featureGateAccess

Expand Down Expand Up @@ -595,15 +587,6 @@ func (ctrl *Controller) syncContainerRuntimeConfig(key string) error {
klog.V(4).Infof("Finished syncing ContainerRuntimeconfig %q (%v)", key, time.Since(startTime))
}()

// create the MC for the drop in default-container-runtime crio.conf file
if err := ctrl.createDefaultContainerRuntimeMC(); err != nil {
return fmt.Errorf("failed to create the crio-default-container-runtime MC: %w", err)
}

if key == forceSyncOnUpgrade {
return nil
}

_, name, err := cache.SplitMetaNamespaceKey(key)
if err != nil {
return err
Expand Down Expand Up @@ -668,8 +651,9 @@ func (ctrl *Controller) syncContainerRuntimeConfig(key string) error {
// If we have seen this generation and the sync didn't fail, then skip
if !isNotFound && cfg.Status.ObservedGeneration >= cfg.Generation && cfg.Status.Conditions[len(cfg.Status.Conditions)-1].Type == mcfgv1.ContainerRuntimeConfigSuccess {
// But we still need to compare the generated controller version because during an upgrade we need a new one
if mc.Annotations[ctrlcommon.GeneratedByControllerVersionAnnotationKey] == version.Hash {
continue
mcCtrlVersion := mc.Annotations[ctrlcommon.GeneratedByControllerVersionAnnotationKey]
if mcCtrlVersion == version.Hash {
return nil
}
}
// Generate the original ContainerRuntimeConfig
Expand Down Expand Up @@ -756,7 +740,6 @@ func (ctrl *Controller) syncContainerRuntimeConfig(key string) error {
klog.Infof("Applied ContainerRuntimeConfig %v on MachineConfigPool %v", key, pool.Name)
ctrlcommon.UpdateStateMetric(ctrlcommon.MCCSubControllerState, "machine-config-controller-container-runtime-config", "Sync Container Runtime Config", pool.Name)
}

if err := ctrl.cleanUpDuplicatedMC(); err != nil {
return err
}
Expand Down Expand Up @@ -1043,92 +1026,6 @@ func registriesConfigIgnition(templateDir string, controllerConfig *mcfgv1.Contr
return &registriesIgn, nil
}

func (ctrl *Controller) createDefaultContainerRuntimeMC() error {
// Check if the crio-default-container-runtime config map exists in the openshift-machine-config-operator namespace
defaultContainerRuntimeCM, err := ctrl.kubeClient.CoreV1().ConfigMaps(ctrl.namespace).Get(context.TODO(), configMapName, metav1.GetOptions{})
if err != nil && !errors.IsNotFound(err) {
return fmt.Errorf("error checking for %s config map: %w", configMapName, err)
}
// If the crio-default-container-runtime config map exists, the MC was already created, so skip creating it again.
if defaultContainerRuntimeCM != nil && !errors.IsNotFound(err) {
return nil
}

sel, err := metav1.LabelSelectorAsSelector(metav1.AddLabelToSelector(&metav1.LabelSelector{}, builtInLabelKey, ""))
if err != nil {
return err
}
// Find all the MachineConfigPools
mcpPoolsAll, err := ctrl.mcpLister.List(sel)
if err != nil {
return err
}

// Create the crio-default-container-runtime MC for all the available pools
for _, pool := range mcpPoolsAll {
if pool.Name != ctrlcommon.MachineConfigPoolMaster && pool.Name != ctrlcommon.MachineConfigPoolWorker {
continue
}
managedKey := getManagedKeyDefaultContainerRuntime(pool)
mc, err := ctrl.client.MachineconfigurationV1().MachineConfigs().Get(context.TODO(), managedKey, metav1.GetOptions{})
if err != nil && !errors.IsNotFound(err) {
return fmt.Errorf("error checking for %s machine config: %w", managedKey, err)
}
// continue to the next MC if this already exists
if mc != nil && !errors.IsNotFound(err) {
continue
}

tempIgnCfg := ctrlcommon.NewIgnConfig()
mc, err = ctrlcommon.MachineConfigFromIgnConfig(pool.Name, managedKey, tempIgnCfg)
if err != nil {
return fmt.Errorf("could not create crio-default-container-runtime MachineConfig from new Ignition config: %w", err)
}
rawRuntimeIgnition, err := json.Marshal(createNewIgnition(createDefaultContainerRuntimeFile()))
if err != nil {
return fmt.Errorf("error marshalling crio-default-container-runtime config ignition: %w", err)
}
mc.Spec.Config.Raw = rawRuntimeIgnition
// Create the crio-default-container-runtime MC
if err := retry.RetryOnConflict(updateBackoff, func() error {
_, err = ctrl.client.MachineconfigurationV1().MachineConfigs().Create(context.TODO(), mc, metav1.CreateOptions{})
return err
}); err != nil {
return fmt.Errorf("could not create MachineConfig for crio-default-container-runtime: %w", err)
}
klog.Infof("Applied default runtime MC %v on MachineConfigPool %v", managedKey, pool.Name)
}

// Create the config map for crio-default-container-runtime so we know that the crio-default-container-runtime MC has been created
if defaultContainerRuntimeCM == nil {
defaultContainerRuntimeCM = &v1.ConfigMap{}
}

defaultContainerRuntimeCM.Name = configMapName
defaultContainerRuntimeCM.Namespace = ctrl.namespace
if _, err := ctrl.kubeClient.CoreV1().ConfigMaps(ctrl.namespace).Create(context.TODO(), defaultContainerRuntimeCM, metav1.CreateOptions{}); err != nil {
return fmt.Errorf("error creating %s config map: %w", configMapName, err)
}
return nil
}

// RunDefaultContainerRuntimeBootstrap creates the crio-default-container-runtime mc on bootstrap
func RunDefaultContainerRuntimeBootstrap(mcpPools []*mcfgv1.MachineConfigPool) ([]*mcfgv1.MachineConfig, error) {
var res []*mcfgv1.MachineConfig
for _, pool := range mcpPools {
if pool.Name != ctrlcommon.MachineConfigPoolMaster && pool.Name != ctrlcommon.MachineConfigPoolWorker {
continue
}
defaultContainerRuntimeIgn := createNewIgnition(createDefaultContainerRuntimeFile())
mc, err := ctrlcommon.MachineConfigFromIgnConfig(pool.Name, getManagedKeyDefaultContainerRuntime(pool), defaultContainerRuntimeIgn)
if err != nil {
return nil, fmt.Errorf("could not create MachineConfig from new Ignition config: %w", err)
}
res = append(res, mc)
}
return res, nil
}

// getValidScopePolicies returns a map[scope]policyRequirement from ClusterImagePolicy
func getValidScopePolicies(clusterImagePolicies []*apicfgv1alpha1.ClusterImagePolicy) (map[string]signature.PolicyRequirements, error) {
clusterScopePolicies := make(map[string]signature.PolicyRequirements)
Expand Down
Loading