|
|
@ -29,6 +29,7 @@ import (
|
|
|
|
"github.com/rancher/wrangler/pkg/apply"
|
|
|
|
"github.com/rancher/wrangler/pkg/apply"
|
|
|
|
"github.com/rancher/wrangler/pkg/condition"
|
|
|
|
"github.com/rancher/wrangler/pkg/condition"
|
|
|
|
"github.com/rancher/wrangler/pkg/generic"
|
|
|
|
"github.com/rancher/wrangler/pkg/generic"
|
|
|
|
|
|
|
|
"github.com/rancher/wrangler/pkg/kv"
|
|
|
|
"k8s.io/apimachinery/pkg/api/equality"
|
|
|
|
"k8s.io/apimachinery/pkg/api/equality"
|
|
|
|
"k8s.io/apimachinery/pkg/api/errors"
|
|
|
|
"k8s.io/apimachinery/pkg/api/errors"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
@ -267,6 +268,7 @@ func RegisterAddonGeneratingHandler(ctx context.Context, controller AddonControl
|
|
|
|
if opts != nil {
|
|
|
|
if opts != nil {
|
|
|
|
statusHandler.opts = *opts
|
|
|
|
statusHandler.opts = *opts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
controller.OnChange(ctx, name, statusHandler.Remove)
|
|
|
|
RegisterAddonStatusHandler(ctx, controller, condition, name, statusHandler.Handle)
|
|
|
|
RegisterAddonStatusHandler(ctx, controller, condition, name, statusHandler.Handle)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -281,7 +283,7 @@ func (a *addonStatusHandler) sync(key string, obj *v1.Addon) (*v1.Addon, error)
|
|
|
|
return obj, nil
|
|
|
|
return obj, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
origStatus := obj.Status
|
|
|
|
origStatus := obj.Status.DeepCopy()
|
|
|
|
obj = obj.DeepCopy()
|
|
|
|
obj = obj.DeepCopy()
|
|
|
|
newStatus, err := a.handler(obj, obj.Status)
|
|
|
|
newStatus, err := a.handler(obj, obj.Status)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -289,16 +291,16 @@ func (a *addonStatusHandler) sync(key string, obj *v1.Addon) (*v1.Addon, error)
|
|
|
|
newStatus = *origStatus.DeepCopy()
|
|
|
|
newStatus = *origStatus.DeepCopy()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
obj.Status = newStatus
|
|
|
|
|
|
|
|
if a.condition != "" {
|
|
|
|
if a.condition != "" {
|
|
|
|
if errors.IsConflict(err) {
|
|
|
|
if errors.IsConflict(err) {
|
|
|
|
a.condition.SetError(obj, "", nil)
|
|
|
|
a.condition.SetError(&newStatus, "", nil)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
a.condition.SetError(obj, "", err)
|
|
|
|
a.condition.SetError(&newStatus, "", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !equality.Semantic.DeepEqual(origStatus, obj.Status) {
|
|
|
|
if !equality.Semantic.DeepEqual(origStatus, &newStatus) {
|
|
|
|
var newErr error
|
|
|
|
var newErr error
|
|
|
|
|
|
|
|
obj.Status = newStatus
|
|
|
|
obj, newErr = a.client.UpdateStatus(obj)
|
|
|
|
obj, newErr = a.client.UpdateStatus(obj)
|
|
|
|
if err == nil {
|
|
|
|
if err == nil {
|
|
|
|
err = newErr
|
|
|
|
err = newErr
|
|
|
@ -315,29 +317,28 @@ type addonGeneratingHandler struct {
|
|
|
|
name string
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (a *addonGeneratingHandler) Handle(obj *v1.Addon, status v1.AddonStatus) (v1.AddonStatus, error) {
|
|
|
|
func (a *addonGeneratingHandler) Remove(key string, obj *v1.Addon) (*v1.Addon, error) {
|
|
|
|
objs, newStatus, err := a.AddonGeneratingHandler(obj, status)
|
|
|
|
if obj != nil {
|
|
|
|
if err != nil {
|
|
|
|
return obj, nil
|
|
|
|
return newStatus, err
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
apply := a.apply
|
|
|
|
obj = &v1.Addon{}
|
|
|
|
|
|
|
|
obj.Namespace, obj.Name = kv.RSplit(key, "/")
|
|
|
|
if !a.opts.DynamicLookup {
|
|
|
|
obj.SetGroupVersionKind(a.gvk)
|
|
|
|
apply = apply.WithStrictCaching()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !a.opts.AllowCrossNamespace && !a.opts.AllowClusterScoped {
|
|
|
|
return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
|
|
|
|
apply = apply.WithSetOwnerReference(true, false).
|
|
|
|
WithOwner(obj).
|
|
|
|
WithDefaultNamespace(obj.GetNamespace()).
|
|
|
|
WithSetID(a.name).
|
|
|
|
WithListerNamespace(obj.GetNamespace())
|
|
|
|
ApplyObjects()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if !a.opts.AllowClusterScoped {
|
|
|
|
func (a *addonGeneratingHandler) Handle(obj *v1.Addon, status v1.AddonStatus) (v1.AddonStatus, error) {
|
|
|
|
apply = apply.WithRestrictClusterScoped()
|
|
|
|
objs, newStatus, err := a.AddonGeneratingHandler(obj, status)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return newStatus, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return newStatus, apply.
|
|
|
|
return newStatus, generic.ConfigureApplyForObject(a.apply, obj, &a.opts).
|
|
|
|
WithOwner(obj).
|
|
|
|
WithOwner(obj).
|
|
|
|
WithSetID(a.name).
|
|
|
|
WithSetID(a.name).
|
|
|
|
ApplyObjects(objs...)
|
|
|
|
ApplyObjects(objs...)
|
|
|
|