update judge work contains serviceExport with work.spec.workload.manifests
Signed-off-by: changzhen <changzhen5@huawei.com>
This commit is contained in:
parent
cd05ffee6e
commit
43fde63b4d
|
@ -81,7 +81,7 @@ func (c *ServiceExportController) Reconcile(ctx context.Context, req controllerr
|
||||||
return controllerruntime.Result{}, nil
|
return controllerruntime.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !helper.IsWorkContains(&work.Status, serviceExportGVK) {
|
if !isWorkContains(work.Spec.Workload.Manifests, serviceExportGVK) {
|
||||||
return controllerruntime.Result{}, nil
|
return controllerruntime.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,6 +105,23 @@ func (c *ServiceExportController) Reconcile(ctx context.Context, req controllerr
|
||||||
return c.buildResourceInformers(cluster)
|
return c.buildResourceInformers(cluster)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isWorkContains checks if the target resource exists in a work.spec.workload.manifests.
|
||||||
|
func isWorkContains(manifests []workv1alpha1.Manifest, targetResource schema.GroupVersionKind) bool {
|
||||||
|
for index := range manifests {
|
||||||
|
workload := &unstructured.Unstructured{}
|
||||||
|
err := workload.UnmarshalJSON(manifests[index].Raw)
|
||||||
|
if err != nil {
|
||||||
|
klog.Errorf("failed to unmarshal work manifests index %d, error is: %v", index, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if targetResource == workload.GroupVersionKind() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// SetupWithManager creates a controller and register to controller manager.
|
// SetupWithManager creates a controller and register to controller manager.
|
||||||
func (c *ServiceExportController) SetupWithManager(mgr controllerruntime.Manager) error {
|
func (c *ServiceExportController) SetupWithManager(mgr controllerruntime.Manager) error {
|
||||||
return controllerruntime.NewControllerManagedBy(mgr).For(&workv1alpha1.Work{}).WithEventFilter(c.PredicateFunc).Complete(c)
|
return controllerruntime.NewControllerManagedBy(mgr).For(&workv1alpha1.Work{}).WithEventFilter(c.PredicateFunc).Complete(c)
|
||||||
|
|
|
@ -268,20 +268,6 @@ func IsResourceApplied(workStatus *workv1alpha1.WorkStatus) bool {
|
||||||
return meta.IsStatusConditionTrue(workStatus.Conditions, workv1alpha1.WorkApplied)
|
return meta.IsStatusConditionTrue(workStatus.Conditions, workv1alpha1.WorkApplied)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsWorkContains checks if the target resource exists in a work.
|
|
||||||
// Note: This function checks the Work object's status to detect the target resource, so the Work should be 'Applied',
|
|
||||||
// otherwise always returns false.
|
|
||||||
func IsWorkContains(workStatus *workv1alpha1.WorkStatus, targetResource schema.GroupVersionKind) bool {
|
|
||||||
for _, manifestStatuses := range workStatus.ManifestStatuses {
|
|
||||||
if targetResource.Group == manifestStatuses.Identifier.Group &&
|
|
||||||
targetResource.Version == manifestStatuses.Identifier.Version &&
|
|
||||||
targetResource.Kind == manifestStatuses.Identifier.Kind {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// BuildStatusRawExtension builds raw JSON by a status map.
|
// BuildStatusRawExtension builds raw JSON by a status map.
|
||||||
func BuildStatusRawExtension(status interface{}) (*runtime.RawExtension, error) {
|
func BuildStatusRawExtension(status interface{}) (*runtime.RawExtension, error) {
|
||||||
statusJSON, err := json.Marshal(status)
|
statusJSON, err := json.Marshal(status)
|
||||||
|
|
Loading…
Reference in New Issue