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

OCPBUGS-47802: OCPBUGS-47801: trying to wait for sub-controllers #4775

Merged
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
2 changes: 2 additions & 0 deletions cmd/machine-config-controller/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ func createControllers(ctx *ctrlcommon.ControllerContext) []ctrlcommon.Controlle
ctx.InformerFactory.Machineconfiguration().V1().MachineConfigPools(),
ctx.InformerFactory.Machineconfiguration().V1().MachineConfigs(),
ctx.InformerFactory.Machineconfiguration().V1().ControllerConfigs(),
ctx.InformerFactory.Machineconfiguration().V1().ContainerRuntimeConfigs(),
ctx.InformerFactory.Machineconfiguration().V1().KubeletConfigs(),
ctx.ClientBuilder.KubeClientOrDie("render-controller"),
ctx.ClientBuilder.MachineConfigClientOrDie("render-controller"),
),
Expand Down
38 changes: 38 additions & 0 deletions pkg/apihelpers/apihelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/klog/v2"
)
Expand Down Expand Up @@ -313,6 +314,43 @@ func IsControllerConfigCompleted(ccName string, ccGetter func(string) (*mcfgv1.C
return fmt.Errorf("ControllerConfig has not completed: completed(%v) running(%v) failing(%v)", completed, running, failing)
}

// AreMCGeneratingSubControllersCompleted checks whether all MC producing sub-controllers are completed
func AreMCGeneratingSubControllersCompleted(crcLister func(labels.Selector) ([]*mcfgv1.ContainerRuntimeConfig, error), mckLister func(labels.Selector) ([]*mcfgv1.KubeletConfig, error), selector labels.Selector) error {

containerConfigs, err := crcLister(selector)
if err != nil {
return err
}
for _, crc := range containerConfigs {
if crc.Generation != crc.Status.ObservedGeneration {
return fmt.Errorf("status for ContainerRuntimeConfig %s is being reported for %d, expecting it for %d", crc.ObjectMeta.Name, crc.Status.ObservedGeneration, crc.Generation)
}

for _, condition := range crc.Status.Conditions {
if condition.Type != mcfgv1.ContainerRuntimeConfigSuccess {
return fmt.Errorf("ContainerRuntimeConfig has not completed")
}
}
}

kubeletConfigs, err := mckLister(selector)
if err != nil {
return err
}
for _, mck := range kubeletConfigs {
if mck.Generation != mck.Status.ObservedGeneration {
return fmt.Errorf("status for KubeletConfig %s is being reported for %d, expecting it for %d", mck.ObjectMeta.Name, mck.Status.ObservedGeneration, mck.Generation)
}

for _, condition := range mck.Status.Conditions {
if condition.Type != mcfgv1.KubeletConfigSuccess {
return fmt.Errorf("KubeletConfig has not completed")
}
}
}
return nil
}

// Merges the cluster's default node disruption policies with the user defined policies, if any.
func MergeClusterPolicies(userDefinedClusterPolicies opv1.NodeDisruptionPolicyConfig) opv1.NodeDisruptionPolicyClusterStatus {

Expand Down
16 changes: 16 additions & 0 deletions pkg/controller/render/render_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ type Controller struct {
ccLister mcfglistersv1.ControllerConfigLister
ccListerSynced cache.InformerSynced

crcLister mcfglistersv1.ContainerRuntimeConfigLister
crcListerSynced cache.InformerSynced

mckLister mcfglistersv1.KubeletConfigLister
mckListerSynced cache.InformerSynced

queue workqueue.RateLimitingInterface
}

Expand All @@ -78,6 +84,8 @@ func New(
mcpInformer mcfginformersv1.MachineConfigPoolInformer,
mcInformer mcfginformersv1.MachineConfigInformer,
ccInformer mcfginformersv1.ControllerConfigInformer,
crcInformer mcfginformersv1.ContainerRuntimeConfigInformer,
mckInformer mcfginformersv1.KubeletConfigInformer,
kubeClient clientset.Interface,
mcfgClient mcfgclientset.Interface,
) *Controller {
Expand Down Expand Up @@ -111,6 +119,10 @@ func New(
ctrl.mcListerSynced = mcInformer.Informer().HasSynced
ctrl.ccLister = ccInformer.Lister()
ctrl.ccListerSynced = ccInformer.Informer().HasSynced
ctrl.crcLister = crcInformer.Lister()
ctrl.crcListerSynced = crcInformer.Informer().HasSynced
ctrl.mckLister = mckInformer.Lister()
ctrl.mckListerSynced = mckInformer.Informer().HasSynced

return ctrl
}
Expand Down Expand Up @@ -429,6 +441,10 @@ func (ctrl *Controller) syncMachineConfigPool(key string) error {
return err
}

if err := apihelpers.AreMCGeneratingSubControllersCompleted(ctrl.crcLister.List, ctrl.mckLister.List, selector); err != nil {
return err
}

mcs, err := ctrl.mcLister.List(selector)
if err != nil {
return err
Expand Down
36 changes: 32 additions & 4 deletions pkg/controller/render/render_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type fixture struct {
mcpLister []*mcfgv1.MachineConfigPool
mcLister []*mcfgv1.MachineConfig
ccLister []*mcfgv1.ControllerConfig
crcLister []*mcfgv1.ContainerRuntimeConfig
mckLister []*mcfgv1.KubeletConfig

actions []core.Action

Expand All @@ -65,11 +67,13 @@ func (f *fixture) newController() *Controller {
i := informers.NewSharedInformerFactory(f.client, noResyncPeriodFunc())

c := New(i.Machineconfiguration().V1().MachineConfigPools(), i.Machineconfiguration().V1().MachineConfigs(),
i.Machineconfiguration().V1().ControllerConfigs(), k8sfake.NewSimpleClientset(), f.client)
i.Machineconfiguration().V1().ControllerConfigs(), i.Machineconfiguration().V1().ContainerRuntimeConfigs(), i.Machineconfiguration().V1().KubeletConfigs(), k8sfake.NewSimpleClientset(), f.client)

c.mcpListerSynced = alwaysReady
c.mcListerSynced = alwaysReady
c.ccListerSynced = alwaysReady
c.crcListerSynced = alwaysReady
c.mckListerSynced = alwaysReady
c.eventRecorder = ctrlcommon.NamespacedEventRecorder(&record.FakeRecorder{})

stopCh := make(chan struct{})
Expand All @@ -91,6 +95,14 @@ func (f *fixture) newController() *Controller {
i.Machineconfiguration().V1().ControllerConfigs().Informer().GetIndexer().Add(m)
}

for _, m := range f.crcLister {
i.Machineconfiguration().V1().ContainerRuntimeConfigs().Informer().GetIndexer().Add(m)
}

for _, m := range f.mckLister {
i.Machineconfiguration().V1().KubeletConfigs().Informer().GetIndexer().Add(m)
}

return c
}

Expand Down Expand Up @@ -184,7 +196,11 @@ func filterInformerActions(actions []core.Action) []core.Action {
action.Matches("list", "controllerconfigs") ||
action.Matches("watch", "controllerconfigs") ||
action.Matches("list", "machineconfigs") ||
action.Matches("watch", "machineconfigs")) {
action.Matches("watch", "machineconfigs") ||
action.Matches("list", "kubeletconfigs") ||
action.Matches("watch", "kubeletconfigs") ||
action.Matches("list", "containerruntimeconfigs") ||
action.Matches("watch", "containerruntimeconfigs")) {
continue
}
ret = append(ret, action)
Expand Down Expand Up @@ -261,8 +277,12 @@ func TestCreatesGeneratedMachineConfig(t *testing.T) {
helpers.NewMachineConfig("05-extra-master", map[string]string{"node-role/master": ""}, "dummy://1", []ign3types.File{files[1]}),
}
cc := newControllerConfig(ctrlcommon.ControllerConfigName)
crc := &mcfgv1.ContainerRuntimeConfig{}
mck := &mcfgv1.KubeletConfig{}

f.ccLister = append(f.ccLister, cc)
f.crcLister = append(f.crcLister, crc)
f.mckLister = append(f.mckLister, mck)
f.mcpLister = append(f.mcpLister, mcp)
f.objects = append(f.objects, mcp)
f.mcLister = append(f.mcLister, mcs...)
Expand Down Expand Up @@ -356,8 +376,12 @@ func TestUpdatesGeneratedMachineConfig(t *testing.T) {
mcp.Spec.Configuration.Name = gmc.Name
mcp.Status.Configuration.Name = gmc.Name

f.ccLister = append(f.ccLister, cc)
crc := &mcfgv1.ContainerRuntimeConfig{}
mck := &mcfgv1.KubeletConfig{}

f.ccLister = append(f.ccLister, cc)
f.crcLister = append(f.crcLister, crc)
f.mckLister = append(f.mckLister, mck)
f.mcpLister = append(f.mcpLister, mcp)
f.objects = append(f.objects, mcp)
f.mcLister = append(f.mcLister, mcs...)
Expand Down Expand Up @@ -469,8 +493,12 @@ func TestDoNothing(t *testing.T) {
mcp.Spec.Configuration.Name = gmc.Name
mcp.Status.Configuration.Name = gmc.Name

f.ccLister = append(f.ccLister, cc)
crc := &mcfgv1.ContainerRuntimeConfig{}
mck := &mcfgv1.KubeletConfig{}

f.ccLister = append(f.ccLister, cc)
f.crcLister = append(f.crcLister, crc)
f.mckLister = append(f.mckLister, mck)
f.mcpLister = append(f.mcpLister, mcp)
f.objects = append(f.objects, mcp)
f.mcLister = append(f.mcLister, mcs...)
Expand Down
2 changes: 2 additions & 0 deletions test/e2e-bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ func createControllers(ctx *ctrlcommon.ControllerContext) []ctrlcommon.Controlle
ctx.InformerFactory.Machineconfiguration().V1().MachineConfigPools(),
ctx.InformerFactory.Machineconfiguration().V1().MachineConfigs(),
ctx.InformerFactory.Machineconfiguration().V1().ControllerConfigs(),
ctx.InformerFactory.Machineconfiguration().V1().ContainerRuntimeConfigs(),
ctx.InformerFactory.Machineconfiguration().V1().KubeletConfigs(),
ctx.ClientBuilder.KubeClientOrDie("render-controller"),
ctx.ClientBuilder.MachineConfigClientOrDie("render-controller"),
),
Expand Down