support DependentOverrides (#157)
Signed-off-by: lihanbo <lihanbo2@huawei.com>
This commit is contained in:
parent
5fa0e7fc7c
commit
6d907af426
|
@ -2,6 +2,7 @@ package propagationpolicy
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
|
@ -58,6 +59,14 @@ func (c *Controller) Reconcile(req controllerruntime.Request) (controllerruntime
|
|||
return controllerruntime.Result{}, nil
|
||||
}
|
||||
|
||||
present, err := c.allDependentOverridesPresent(policy)
|
||||
if err != nil {
|
||||
return controllerruntime.Result{Requeue: true}, err
|
||||
}
|
||||
if !present {
|
||||
return controllerruntime.Result{Requeue: true}, fmt.Errorf("the specific overrides which current PropagationPolicy %v/%v rely on are not all present", policy.GetNamespace(), policy.GetName())
|
||||
}
|
||||
|
||||
result, err := c.syncPolicy(policy)
|
||||
if err != nil {
|
||||
return result, err
|
||||
|
@ -315,6 +324,23 @@ func (c *Controller) ensurePropagationBinding(policy *v1alpha1.PropagationPolicy
|
|||
return err
|
||||
}
|
||||
|
||||
// allDependentOverridesPresent will ensure the specify overrides which current PropagationPolicy rely on are present
|
||||
func (c *Controller) allDependentOverridesPresent(policy *v1alpha1.PropagationPolicy) (bool, error) {
|
||||
for _, override := range policy.Spec.DependentOverrides {
|
||||
overrideObj := &v1alpha1.OverridePolicy{}
|
||||
if err := c.Client.Get(context.TODO(), client.ObjectKey{Namespace: policy.Namespace, Name: override}, overrideObj); err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
klog.Warningf("The specific override policy %v/%v which current PropagationPolicy %v/%v rely on is not present", policy.Namespace, override, policy.Namespace, policy.Name)
|
||||
return false, nil
|
||||
}
|
||||
klog.Errorf("Failed to get override policy %v/%v, Error: %v", policy.Namespace, override, err)
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// SetupWithManager creates a controller and register to controller manager.
|
||||
func (c *Controller) SetupWithManager(mgr controllerruntime.Manager) error {
|
||||
return controllerruntime.NewControllerManagedBy(mgr).For(&v1alpha1.PropagationPolicy{}).Complete(c)
|
||||
|
|
Loading…
Reference in New Issue