Skip to content

Commit

Permalink
BZ1714769: fix kubeletconfig zero MCP errors
Browse files Browse the repository at this point in the history
Do not requeue the key if there are zero MCPs. Prevents multiple status
updates and will not succeed.

ref: https://bugzilla.redhat.com/show_bug.cgi?id=1714769
  • Loading branch information
rphillips committed Jun 3, 2019
1 parent fb707ca commit c0f7151
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions pkg/controller/kubelet-config/kubelet_config_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kubeletconfig

import (
"encoding/json"
"errors"
"fmt"
"reflect"
"time"
Expand All @@ -12,7 +13,7 @@ import (
"github.com/vincent-petithory/dataurl"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
macherrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -59,6 +60,8 @@ var updateBackoff = wait.Backoff{
Jitter: 1.0,
}

var errCouldNotFindMCPSet = errors.New("could not find any MachineConfigPool set for KubeletConfig")

// A list of fields a user cannot set within the KubeletConfig CR. If a user
// were to set these values, then the system may become unrecoverable (ie: not
// recover after a reboot).
Expand Down Expand Up @@ -156,7 +159,7 @@ func New(

ctrl.featLister = featInformer.Lister()
ctrl.featListerSynced = featInformer.Informer().HasSynced

ctrl.patchKubeletConfigsFunc = ctrl.patchKubeletConfigs

return ctrl
Expand Down Expand Up @@ -236,7 +239,7 @@ func (ctrl *Controller) cascadeDelete(cfg *mcfgv1.KubeletConfig) error {
}
mcName := cfg.GetFinalizers()[0]
err := ctrl.client.Machineconfiguration().MachineConfigs().Delete(mcName, &metav1.DeleteOptions{})
if err != nil && !errors.IsNotFound(err) {
if err != nil && !macherrors.IsNotFound(err) {
return err
}
if err := ctrl.popFinalizerFromKubeletConfig(cfg); err != nil {
Expand Down Expand Up @@ -284,7 +287,7 @@ func (ctrl *Controller) processNextWorkItem() bool {
}

func (ctrl *Controller) handleErr(err error, key interface{}) {
if err == nil {
if err == nil || err == errCouldNotFindMCPSet {
ctrl.queue.Forget(key)
return
}
Expand Down Expand Up @@ -373,7 +376,7 @@ func (ctrl *Controller) syncKubeletConfig(key string) error {

// Fetch the KubeletConfig
cfg, err := ctrl.mckLister.Get(name)
if errors.IsNotFound(err) {
if macherrors.IsNotFound(err) {
glog.V(2).Infof("KubeletConfig %v has been deleted", key)
return nil
}
Expand Down Expand Up @@ -415,7 +418,7 @@ func (ctrl *Controller) syncKubeletConfig(key string) error {
}

features, err := ctrl.featLister.Get(clusterFeatureInstanceName)
if errors.IsNotFound(err) {
if macherrors.IsNotFound(err) {
features = createNewDefaultFeatureGate()
} else if err != nil {
glog.V(2).Infof("%v", err)
Expand All @@ -434,10 +437,10 @@ func (ctrl *Controller) syncKubeletConfig(key string) error {
// Get MachineConfig
managedKey := getManagedKubeletConfigKey(pool)
mc, err := ctrl.client.Machineconfiguration().MachineConfigs().Get(managedKey, metav1.GetOptions{})
if err != nil && !errors.IsNotFound(err) {
if err != nil && !macherrors.IsNotFound(err) {
return ctrl.syncStatusOnly(cfg, err, "could not find MachineConfig: %v", managedKey)
}
isNotFound := errors.IsNotFound(err)
isNotFound := macherrors.IsNotFound(err)
// Generate the original KubeletConfig
originalKubeletIgn, err := ctrl.generateOriginalKubeletConfig(role)
if err != nil {
Expand Down Expand Up @@ -502,7 +505,7 @@ func (ctrl *Controller) syncKubeletConfig(key string) error {
func (ctrl *Controller) popFinalizerFromKubeletConfig(kc *mcfgv1.KubeletConfig) error {
return retry.RetryOnConflict(updateBackoff, func() error {
newcfg, err := ctrl.mckLister.Get(kc.Name)
if errors.IsNotFound(err) {
if macherrors.IsNotFound(err) {
return nil
}
if err != nil {
Expand Down Expand Up @@ -538,7 +541,7 @@ func (ctrl *Controller) patchKubeletConfigs(name string, patch []byte) error {
func (ctrl *Controller) addFinalizerToKubeletConfig(kc *mcfgv1.KubeletConfig, mc *mcfgv1.MachineConfig) error {
return retry.RetryOnConflict(updateBackoff, func() error {
newcfg, err := ctrl.mckLister.Get(kc.Name)
if errors.IsNotFound(err) {
if macherrors.IsNotFound(err) {
return nil
}
if err != nil {
Expand Down Expand Up @@ -586,7 +589,7 @@ func (ctrl *Controller) getPoolsForKubeletConfig(config *mcfgv1.KubeletConfig) (
}

if len(pools) == 0 {
return nil, fmt.Errorf("could not find any MachineConfigPool set for KubeletConfig %s", config.Name)
return nil, errCouldNotFindMCPSet
}

return pools, nil
Expand Down

0 comments on commit c0f7151

Please sign in to comment.