Merge pull request #72919 from liggitt/crd-quiet-conflict

Avoid logging normal conflict/notfound error responses in CRD controllers
k3s-v1.15.3
Kubernetes Prow Robot 2019-03-19 19:00:38 -07:00 committed by GitHub
commit 86f6279bb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 1 deletions

View File

@ -135,6 +135,10 @@ func (ec *EstablishingController) sync(key string) error {
// Update server with new CRD condition.
_, err = ec.crdClient.CustomResourceDefinitions().UpdateStatus(crd)
if apierrors.IsNotFound(err) || apierrors.IsConflict(err) {
// deleted or changed in the meantime, we'll get called again
return nil
}
if err != nil {
return err
}

View File

@ -116,6 +116,10 @@ func (c *CRDFinalizer) sync(key string) error {
Message: "CustomResource deletion is in progress",
})
crd, err = c.crdClient.CustomResourceDefinitions().UpdateStatus(crd)
if apierrors.IsNotFound(err) || apierrors.IsConflict(err) {
// deleted or changed in the meantime, we'll get called again
return nil
}
if err != nil {
return err
}
@ -143,6 +147,10 @@ func (c *CRDFinalizer) sync(key string) error {
apiextensions.CRDRemoveFinalizer(crd, apiextensions.CustomResourceCleanupFinalizer)
crd, err = c.crdClient.CustomResourceDefinitions().UpdateStatus(crd)
if apierrors.IsNotFound(err) || apierrors.IsConflict(err) {
// deleted or changed in the meantime, we'll get called again
return nil
}
if err != nil {
return err
}

View File

@ -261,6 +261,10 @@ func (c *NamingConditionController) sync(key string) error {
apiextensions.SetCRDCondition(crd, establishedCondition)
updatedObj, err := c.crdClient.CustomResourceDefinitions().UpdateStatus(crd)
if apierrors.IsNotFound(err) || apierrors.IsConflict(err) {
// deleted or changed in the meantime, we'll get called again
return nil
}
if err != nil {
return err
}

View File

@ -28,6 +28,7 @@ go_library(
importpath = "k8s.io/kube-aggregator/pkg/controllers/autoregister",
deps = [
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",

View File

@ -25,6 +25,7 @@ import (
"k8s.io/klog"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
@ -240,6 +241,10 @@ func (c *autoRegisterController) checkAPIService(name string) (err error) {
// we don't have an entry and we do want one (2B,2C)
case apierrors.IsNotFound(err) && desired != nil:
_, err := c.apiServiceClient.APIServices().Create(desired)
if apierrors.IsAlreadyExists(err) {
// created in the meantime, we'll get called again
return nil
}
return err
// we aren't trying to manage this APIService (3A,3B,3C)
@ -256,7 +261,13 @@ func (c *autoRegisterController) checkAPIService(name string) (err error) {
// we have a spurious APIService that we're managing, delete it (5A,6A)
case desired == nil:
return c.apiServiceClient.APIServices().Delete(curr.Name, nil)
opts := &metav1.DeleteOptions{Preconditions: metav1.NewUIDPreconditions(string(curr.UID))}
err := c.apiServiceClient.APIServices().Delete(curr.Name, opts)
if apierrors.IsNotFound(err) || apierrors.IsConflict(err) {
// deleted or changed in the meantime, we'll get called again
return nil
}
return err
// if the specs already match, nothing for us to do
case reflect.DeepEqual(curr.Spec, desired.Spec):
@ -267,6 +278,10 @@ func (c *autoRegisterController) checkAPIService(name string) (err error) {
apiService := curr.DeepCopy()
apiService.Spec = desired.Spec
_, err = c.apiServiceClient.APIServices().Update(apiService)
if apierrors.IsNotFound(err) || apierrors.IsConflict(err) {
// deleted or changed in the meantime, we'll get called again
return nil
}
return err
}