Unverified Commit b9cb8fa5 authored by wyike's avatar wyike Committed by GitHub
Browse files

fix enable addon cannot update definition bug (#4684)

Signed-off-by: default avatar楚岳 <wangyike.wyk@alibaba-inc.com>
Signed-off-by: default avatar楚岳 <wangyike.wyk@alibaba-inc.com>
parent 8df436aa
Showing with 9 additions and 5 deletions
+9 -5
......@@ -423,9 +423,12 @@ var _ = Describe("test override defs of addon", func() {
u := unstructured.Unstructured{Object: compUnstructured}
u.SetAPIVersion(v1beta1.SchemeGroupVersion.String())
u.SetKind(v1beta1.ComponentDefinitionKind)
u.SetLabels(map[string]string{"testUpdateLabel": "test"})
c, err := checkConflictDefs(ctx, k8sClient, []*unstructured.Unstructured{&u}, app.GetName())
Expect(err).Should(BeNil())
Expect(len(c)).Should(BeEquivalentTo(1))
// guarantee checkConflictDefs won't change source definition
Expect(u.GetLabels()["testUpdateLabel"]).Should(BeEquivalentTo("test"))
u.SetName("rollout")
c, err = checkConflictDefs(ctx, k8sClient, []*unstructured.Unstructured{&u}, app.GetName())
......
......@@ -444,20 +444,21 @@ func generateAnnotation(meta *Meta) map[string]string {
func checkConflictDefs(ctx context.Context, k8sClient client.Client, defs []*unstructured.Unstructured, appName string) (map[string]string, error) {
res := map[string]string{}
for _, def := range defs {
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(def), def)
checkDef := def.DeepCopy()
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(checkDef), checkDef)
if err == nil {
owner := metav1.GetControllerOf(def)
owner := metav1.GetControllerOf(checkDef)
if owner == nil || owner.Kind != v1beta1.ApplicationKind {
res[def.GetName()] = fmt.Sprintf("definition: %s already exist and not belong to any addon \n", def.GetName())
res[checkDef.GetName()] = fmt.Sprintf("definition: %s already exist and not belong to any addon \n", checkDef.GetName())
continue
}
if owner.Name != appName {
// if addon not belong to an addon or addon name is another one, we should put them in result
res[def.GetName()] = fmt.Sprintf("definition: %s in this addon already exist in %s \n", def.GetName(), addon.AppName2Addon(appName))
res[checkDef.GetName()] = fmt.Sprintf("definition: %s in this addon already exist in %s \n", checkDef.GetName(), addon.AppName2Addon(appName))
}
}
if err != nil && !errors2.IsNotFound(err) {
return nil, errors.Wrapf(err, "check definition %s", def.GetName())
return nil, errors.Wrapf(err, "check definition %s", checkDef.GetName())
}
}
return res, nil
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment