Skip to content

fix initial race between template and render sub-controllers #338

Closed

Description

@cgwalters

In progress PR: #385


Even with the delay from #303
we've still been seeing races;
#337
is a further band-aid but obviously not a complete solution.

Currently the template controller generates 3 fragments (base, ssh, kubelet) and my osimage work is about to extend that to 4.

The render controller can see any from 1 to 3 (or 4 post-osimageurl) MCs.

One approach is for the template controller to only generate 00-{master,worker}. That gives us atomicity. We could easily do this by just appending the Ignition internally.

This is primarily an issue on initial cluster bringup; hopefully the work that landed to have the controller only render MCs from its own version addresses upgrade issues.

Another solution would be for the render sub-controller to wait until the template sub-controller has signaled that it's done an initial complete generation.

Activity

  1. kikisdeliveryservice commented on Jan 22, 2019

    @kikisdeliveryservice
    Contributor

    Example logs from the race seen today:

    $ oc -n openshift-machine-config-operator logs deploy/machine-config-controller
    Found 2 pods, using pod/machine-config-controller-86f898f7cf-2d9g6
    I0122 18:40:02.844556       1 start.go:45] Version: 3.11.0-490-g8e01f051-dirty
    I0122 18:40:03.044480       1 leaderelection.go:185] attempting to acquire leader lease  openshift-machine-config-operator/machine-config-controller...
    E0122 18:41:59.198607       1 event.go:259] Could not construct reference to: '&v1.ConfigMap{TypeMeta:v1.TypeMeta{Kind:"", APIVersion:""}, ObjectMeta:v1.ObjectMeta{Name:"machine-config-controller", GenerateName:"", Namespace:"openshift-machine-config-operator", SelfLink:"/api/v1/namespaces/openshift-machine-config-operator/configmaps/machine-config-controller", UID:"dcfef82d-1e74-11e9-a459-06fe22aa98cc", ResourceVersion:"5447", Generation:0, CreationTimestamp:v1.Time{Time:time.Time{wall:0x0, ext:63683779088, loc:(*time.Location)(0x1d613a0)}}, DeletionTimestamp:(*v1.Time)(nil), DeletionGracePeriodSeconds:(*int64)(nil), Labels:map[string]string(nil), Annotations:map[string]string{"control-plane.alpha.kubernetes.io/leader":"{\"holderIdentity\":\"machine-config-controller-86f898f7cf-2d9g6_21416016-1e75-11e9-8feb-0a580a800014\",\"leaseDurationSeconds\":90,\"acquireTime\":\"2019-01-22T18:41:59Z\",\"renewTime\":\"2019-01-22T18:41:59Z\",\"leaderTransitions\":1}"}, OwnerReferences:[]v1.OwnerReference(nil), Initializers:(*v1.Initializers)(nil), Finalizers:[]string(nil), ClusterName:""}, Data:map[string]string(nil), BinaryData:map[string][]uint8(nil)}' due to: 'no kind is registered for the type v1.ConfigMap'. Will not report event: 'Normal' 'LeaderElection' 'machine-config-controller-86f898f7cf-2d9g6_21416016-1e75-11e9-8feb-0a580a800014 became leader'
    I0122 18:41:59.244145       1 leaderelection.go:194] successfully acquired lease openshift-machine-config-operator/machine-config-controller
    I0122 18:41:59.344649       1 template_controller.go:111] Starting MachineConfigController-TemplateController
    I0122 18:41:59.444935       1 render_controller.go:113] Starting MachineConfigController-RenderController
    I0122 18:41:59.544014       1 node_controller.go:117] Starting MachineConfigController-NodeController
    I0122 18:41:59.545713       1 kubelet_config_controller.go:128] Starting MachineConfigController-KubeletConfigController
    I0122 18:42:02.944675       1 node_controller.go:336] Error syncing machineconfigpool master: Operation cannot be fulfilled on machineconfigpools.machineconfiguration.openshift.io "master": the object has been modified; please apply your changes to the latest version and try again
    
  2. kikisdeliveryservice commented on Jan 22, 2019

    @kikisdeliveryservice
    Contributor

    More:

    $ oc get machineconfigpools -o yaml master
    apiVersion: machineconfiguration.openshift.io/v1
    kind: MachineConfigPool
    metadata:
      creationTimestamp: 2019-01-22T18:37:50Z
      generation: 1
      labels:
        operator.machineconfiguration.openshift.io/required-for-upgrade: ""
      name: master
      resourceVersion: "5477"
      selfLink: /apis/machineconfiguration.openshift.io/v1/machineconfigpools/master
      uid: d29b8fdd-1e74-11e9-a7f8-06ee3187d02c
    spec:
      machineConfigSelector:
        matchLabels:
          machineconfiguration.openshift.io/role: master
      machineSelector:
        matchLabels:
          node-role.kubernetes.io/master: ""
      maxUnavailable: null
      paused: false
    status:
      conditions:
      - lastTransitionTime: 2019-01-22T18:38:32Z
        message: ""
        reason: ""
        status: "False"
        type: Degraded
      - lastTransitionTime: 2019-01-22T18:42:02Z
        message: ""
        reason: ""
        status: "False"
        type: Updated
      - lastTransitionTime: 2019-01-22T18:42:02Z
        message: ""
        reason: All nodes are updating to master-34ad236a2bd02dcebad68b4de50cf890
        status: "True"
        type: Updating
      configuration:
        name: master-34ad236a2bd02dcebad68b4de50cf890
        source:
        - apiVersion: machineconfiguration.openshift.io/v1
          kind: MachineConfig
          name: 00-master
        - apiVersion: machineconfiguration.openshift.io/v1
          kind: MachineConfig
          name: 00-master-ssh
        - apiVersion: machineconfiguration.openshift.io/v1
          kind: MachineConfig
          name: 01-master-kubelet
      machineCount: 3
      observedGeneration: 1
      readyMachineCount: 2
      unavailableMachineCount: 1
      updatedMachineCount: 3
    
    $ oc get machineconfig
    NAME                                      GENERATEDBYCONTROLLER        IGNITIONVERSION   CREATED   OSIMAGEURL
    00-master                                 3.11.0-490-g8e01f051-dirty   2.2.0             4h        
    00-master-ssh                             3.11.0-490-g8e01f051-dirty                     4h        
    00-worker                                 3.11.0-490-g8e01f051-dirty   2.2.0             4h        
    00-worker-ssh                             3.11.0-490-g8e01f051-dirty                     4h        
    01-master-kubelet                         3.11.0-490-g8e01f051-dirty   2.2.0             4h        
    01-worker-kubelet                         3.11.0-490-g8e01f051-dirty   2.2.0             4h        
    master-34ad236a2bd02dcebad68b4de50cf890   3.11.0-490-g8e01f051-dirty   2.2.0             4h        
    master-d3bff643d18e4e27827cd2c1448c5498   3.11.0-490-g8e01f051-dirty   2.2.0             4h        
    worker-6d990a993046eefa718311dbb4c2a28a   3.11.0-490-g8e01f051-dirty   2.2.0             4h
    
  3. cgwalters commented on Jan 22, 2019

    @cgwalters
    MemberAuthor

    (The "just merge them" approach would be trivial for ssh which is part of the template code, but not for kubelet which is currently structured as a sub-controller)

  4. cgwalters commented on Jan 23, 2019

    @cgwalters
    MemberAuthor

    One thing that came up in conversation about this issue is that things fail rather badly if we don't include the kubelet config in the rendered config, as it means the node will drop out of the cluster. I've seen this happen in some PRs myself (pods going NodeLost); it's particularly bad if it hits a master.

  5. kikisdeliveryservice commented on Jan 24, 2019

    @kikisdeliveryservice
    Contributor

    Since #337 landed I no longer see I0122 20:03:10.258500 1 node_controller.go:336] Error syncing machineconfigpool worker: Operation cannot be fulfilled on machineconfigpools.machineconfiguration.openshift.io "worker": the object has been modified; please apply your changes to the latest version and try again in my MCC logs.

  6. cgwalters commented on Jan 25, 2019

    @cgwalters
    MemberAuthor

    Looks like this PR hit it too: https://gcsweb-ci.svc.ci.openshift.org/gcs/origin-ci-test/pr-logs/pull/21843/pull-ci-openshift-origin-master-e2e-aws/2817/artifacts/e2e-aws/pods/

    I0125 03:43:54.029457       1 render_controller.go:446] Generated machineconfig master-a7afd43bc42080ed79f84371be9e820d from 2 configs: [{MachineConfig  00-master  machineconfiguration.openshift.io/v1  } {MachineConfig  00-master-ssh  machineconfiguration.openshift.io/v1  }]
    ...
    I0125 03:43:59.229415       1 render_controller.go:446] Generated machineconfig master-a07f4e4d61b52eda1488d2ce5643b4ec from 3 configs: [{MachineConfig  00-master  machineconfiguration.openshift.io/v1  } {MachineConfig  00-master-ssh  machineconfiguration.openshift.io/v1  } {MachineConfig  01-master-kubelet  machineconfiguration.openshift.io/v1  }]
    
  7. kikisdeliveryservice commented on Jan 25, 2019

    @kikisdeliveryservice
    Contributor

    See also PR #339 for work related to this issue.

  8. cgwalters commented on Jan 27, 2019

    @cgwalters
    MemberAuthor

    @abhinavdahiya Do we think #339 fixed this?

  9. cgwalters commented on Feb 1, 2019

    @cgwalters
    MemberAuthor

    Still seeing this even after #339 - in a libvirt cluster I just ran:

    $ oc get clusterversion
    NAME      VERSION                           AVAILABLE   PROGRESSING   SINCE   STATUS
    version   4.0.0-0.alpha-2019-02-01-115115   False       True          32m     Unable to apply 4.0.0-0.alpha-2019-02-01-115115: some resources could not be updated
    $ oc logs -f pods/machine-config-controller-6658fd68d9-dkpxt
    I0201 14:21:20.802954       1 start.go:46] Version: 3.11.0-536-gf31d48ff-dirty   
    ...
    I0201 14:21:30.196444       1 render_controller.go:456] Generated machineconfig master-9b8909fd513079c88a5ab4eb68828e4d from 2 configs: [{MachineConfig  00-master  machineconfiguration.openshift.io/v1  } {Machin
    eConfig  00-master-ssh  machineconfiguration.openshift.io/v1  }]
    I0201 14:21:30.202551       1 node_controller.go:345] Error syncing machineconfigpool master: Empty Current MachineConfig
    I0201 14:21:30.202860       1 node_controller.go:345] Error syncing machineconfigpool worker: Empty Current MachineConfig
    I0201 14:21:30.212499       1 render_controller.go:456] Generated machineconfig worker-1f94b948869773414c536072199f14e9 from 2 configs: [{MachineConfig  00-worker  machineconfiguration.openshift.io/v1  } {Machin
    eConfig  00-worker-ssh  machineconfiguration.openshift.io/v1  }]
    I0201 14:21:35.501860       1 render_controller.go:456] Generated machineconfig worker-5c652bf4aa959268898a2b7a2aec8b3c from 3 configs: [{MachineConfig  00-worker  machineconfiguration.openshift.io/v1  } {Machin
    eConfig  00-worker-ssh  machineconfiguration.openshift.io/v1  } {MachineConfig  01-worker-kubelet  machineconfiguration.openshift.io/v1  }]
    I0201 14:21:36.006910       1 render_controller.go:456] Generated machineconfig master-e74f1e67fd05f17fe20810fc695b66c1 from 3 configs: [{MachineConfig  00-master  machineconfiguration.openshift.io/v1  } {Machin
    eConfig  00-master-ssh  machineconfiguration.openshift.io/v1  } {MachineConfig  01-master-kubelet  machineconfiguration.openshift.io/v1  }]
    

    And f31d48f definitely includes #339

  10. cgwalters commented on Feb 1, 2019

    @cgwalters
    MemberAuthor

    Maybe rather than starting all of the sub-controllers concurrently, we want to do something like:

    • Start all sub-generators [today kubelet, could also think of ssh this way]
    • Start the render controller
    • Start the node controller

    And each phase waits for readiness. That way the render controller will always see a full run of our internal MCs. And the node controller can't do anything until something is rendered, so there's no point spamming logs that the pool has an empty MC.

  11. cgwalters commented on Feb 5, 2019

    @cgwalters
    MemberAuthor

    Sketching this out:

    diff --git a/cmd/machine-config-controller/start.go b/cmd/machine-config-controller/start.go
    index d488527..9a88ede 100644
    --- a/cmd/machine-config-controller/start.go
    +++ b/cmd/machine-config-controller/start.go
    @@ -3,6 +3,7 @@ package main
     import (
     	"context"
     	"flag"
    +	"sync"
     
     	"github.com/golang/glog"
     	"github.com/openshift/machine-config-operator/cmd/common"
    @@ -79,6 +80,9 @@ func runStartCmd(cmd *cobra.Command, args []string) {
     }
     
     func startControllers(ctx *common.ControllerContext) error {
    +
    +	var readyFlag sync.WaitGroup
    +
     	// Our primary MCs come from here
     	go template.New(
     		rootOpts.templates,
    @@ -86,7 +90,9 @@ func startControllers(ctx *common.ControllerContext) error {
     		ctx.InformerFactory.Machineconfiguration().V1().MachineConfigs(),
     		ctx.ClientBuilder.KubeClientOrDie("template-controller"),
     		ctx.ClientBuilder.MachineConfigClientOrDie("template-controller"),
    +		readyFlag,
     	).Run(2, ctx.Stop)
    +	readyFlag.Add(1)
     
     	// Add all "sub-renderers here"
     	go kubeletconfig.New(
    @@ -96,7 +102,12 @@ func startControllers(ctx *common.ControllerContext) error {
     		ctx.InformerFactory.Machineconfiguration().V1().KubeletConfigs(),
     		ctx.ClientBuilder.KubeClientOrDie("kubelet-config-controller"),
     		ctx.ClientBuilder.MachineConfigClientOrDie("kubelet-config-controller"),
    +		readyFlag,
     	).Run(2, ctx.Stop)
    +	readyFlag.Add(1)
    +
    +	// Wait for the MC fragments before starting the renderer
    +	readyFlag.Wait()
     
     	// The renderer creates "rendered" MCs from the MC fragments generated by
     	// the above sub-controllers, which are then consumed by the node controller
    diff --git a/pkg/controller/kubelet-config/kubelet_config_controller.go b/pkg/controller/kubelet-config/kubelet_config_controller.go
    index 67f36fb..aba8e44 100644
    --- a/pkg/controller/kubelet-config/kubelet_config_controller.go
    +++ b/pkg/controller/kubelet-config/kubelet_config_controller.go
    @@ -6,6 +6,7 @@ import (
     	"path/filepath"
     	"reflect"
     	"time"
    +	"sync"
     
     	ignv2_2types "github.com/coreos/ignition/config/v2_2/types"
     	"github.com/golang/glog"
    @@ -73,6 +74,7 @@ type Controller struct {
     
     	client        mcfgclientset.Interface
     	eventRecorder record.EventRecorder
    +	readyFlag     *sync.WaitGroup
     
     	syncHandler          func(mcp string) error
     	enqueueKubeletConfig func(*mcfgv1.KubeletConfig)
    @@ -97,6 +99,7 @@ func New(
     	mkuInformer mcfginformersv1.KubeletConfigInformer,
     	kubeClient clientset.Interface,
     	mcfgClient mcfgclientset.Interface,
    +	readyFlag  sync.WaitGroup,
     ) *Controller {
     	eventBroadcaster := record.NewBroadcaster()
     	eventBroadcaster.StartLogging(glog.Infof)
    @@ -127,6 +130,8 @@ func New(
     	ctrl.mckLister = mkuInformer.Lister()
     	ctrl.mckListerSynced = mkuInformer.Informer().HasSynced
     
    +	ctrl.readyFlag = &readyFlag
    +
     	return ctrl
     }
     
    @@ -409,6 +414,11 @@ func (ctrl *Controller) syncKubeletConfig(key string) error {
     		glog.Infof("Applied KubeletConfig %v on MachineConfigPool %v", key, pool.Name)
     	}
     
    +	if ctrl.readyFlag != nil {
    +		ctrl.readyFlag.Done()
    +		ctrl.readyFlag = nil
    +	}
    +
     	return ctrl.syncStatusOnly(cfg, nil)
     }
     
    diff --git a/pkg/controller/template/template_controller.go b/pkg/controller/template/template_controller.go
    index f7c9d27..936174b 100644
    --- a/pkg/controller/template/template_controller.go
    +++ b/pkg/controller/template/template_controller.go
    @@ -6,6 +6,7 @@ import (
     	"fmt"
     	"sort"
     	"time"
    +	"sync"
     
     	"github.com/golang/glog"
     	"github.com/openshift/machine-config-operator/lib/resourceapply"
    @@ -46,6 +47,7 @@ type Controller struct {
     	client        mcfgclientset.Interface
     	kubeClient    clientset.Interface
     	eventRecorder record.EventRecorder
    +	readyFlag     *sync.WaitGroup
     
     	syncHandler             func(ccKey string) error
     	enqueueControllerConfig func(*mcfgv1.ControllerConfig)
    @@ -66,6 +68,7 @@ func New(
     	mcInformer mcfginformersv1.MachineConfigInformer,
     	kubeClient clientset.Interface,
     	mcfgClient mcfgclientset.Interface,
    +	readyFlag  sync.WaitGroup,
     ) *Controller {
     	eventBroadcaster := record.NewBroadcaster()
     	eventBroadcaster.StartLogging(glog.Infof)
    @@ -100,6 +103,8 @@ func New(
     	ctrl.ccListerSynced = ccInformer.Informer().HasSynced
     	ctrl.mcListerSynced = mcInformer.Informer().HasSynced
     
    +	ctrl.readyFlag = &readyFlag
    +
     	return ctrl
     }
     
    @@ -362,6 +367,10 @@ func (ctrl *Controller) syncControllerConfig(key string) error {
     		}
     		if updated {
     			glog.V(4).Infof("Machineconfig %s was updated", mcs[idx].Name)
    +			if ctrl.readyFlag != nil {
    +				ctrl.readyFlag.Done()
    +				ctrl.readyFlag = nil
    +			}
     		}
     	}
     
    
  12. runcom commented on Mar 17, 2019

    @runcom
    Member

    fix here 9e3ad65 in #482 (have the render controller try and error till the template controller is done, more in line with the whole controller pylosophy). Logs with proof that we're not waiting on the template controller is here:

    I0317 16:27:21.495296       1 node_controller.go:383] Pool master is unconfigured, pausing 5s for renderer to initialize
    I0317 16:27:21.495462       1 node_controller.go:383] Pool worker is unconfigured, pausing 5s for renderer to initialize
    I0317 16:27:21.495537       1 render_controller.go:380] Error syncing machineconfigpool master: ControllerConfig has not completed: completed(false) running(false) failing(true)
    I0317 16:27:21.495584       1 render_controller.go:380] Error syncing machineconfigpool worker: ControllerConfig has not completed: completed(false) running(false) failing(true)
    I0317 16:27:21.501140       1 render_controller.go:380] Error syncing machineconfigpool master: ControllerConfig has not completed: completed(false) running(false) failing(true)
    I0317 16:27:21.501180       1 render_controller.go:380] Error syncing machineconfigpool worker: ControllerConfig has not completed: completed(false) running(false) failing(true)
    I0317 16:27:21.511368       1 render_controller.go:380] Error syncing machineconfigpool master: ControllerConfig has not completed: completed(false) running(false) failing(true)
    I0317 16:27:21.511407       1 render_controller.go:380] Error syncing machineconfigpool worker: ControllerConfig has not completed: completed(false) running(false) failing(true)
    I0317 16:27:21.531622       1 render_controller.go:380] Error syncing machineconfigpool master: ControllerConfig has not completed: completed(false) running(false) failing(true)
    I0317 16:27:21.531647       1 render_controller.go:380] Error syncing machineconfigpool worker: ControllerConfig has not completed: completed(false) running(false) failing(true)
    I0317 16:27:21.571897       1 render_controller.go:380] Error syncing machineconfigpool worker: ControllerConfig has not completed: completed(false) running(false) failing(true)
    I0317 16:27:21.571897       1 render_controller.go:380] Error syncing machineconfigpool master: ControllerConfig has not completed: completed(false) running(false) failing(true)
    I0317 16:27:21.671461       1 render_controller.go:500] Generated machineconfig worker-b058168e9ec42a1704343e84bb2dc7eb from 4 configs: [{MachineConfig  00-worker  machineconfiguration.openshift.io/v1  } {MachineConfig  00-worker-ssh  machineconfiguration.openshift.io/v1  } {MachineConfig  01-worker-container-runtime  machineconfiguration.openshift.io/v1  } {MachineConfig  01-worker-kubelet  machineconfiguration.openshift.io/v1  }]
    I0317 16:27:21.684235       1 render_controller.go:500] Generated machineconfig master-34908aca2b6075843cc77cd59449a0df from 4 configs: [{MachineConfig  00-master  machineconfiguration.openshift.io/v1  } {MachineConfig  00-master-ssh  machineconfiguration.openshift.io/v1  } {MachineConfig  01-master-container-runtime  machineconfiguration.openshift.io/v1  } {MachineConfig  01-master-kubelet  machineconfiguration.openshift.io/v1  }]
    
  13. added a commit that references this issue on Apr 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions