mirror of https://github.com/k3s-io/k3s
Merge pull request #72919 from liggitt/crd-quiet-conflict
Avoid logging normal conflict/notfound error responses in CRD controllersk3s-v1.15.3
commit
86f6279bb9
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue