Fix: fix addon bond component annotaion (#4571)

* fix miss spell annotation

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>

* add comments

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>

* fix golint

Signed-off-by: 楚岳 <wangyike.wyk@alibaba-inc.com>
This commit is contained in:
wyike
2022-08-08 11:49:48 +08:00
committed by GitHub
parent 2d8cb1278c
commit db26a037f3
3 changed files with 26 additions and 5 deletions

View File

@@ -482,10 +482,16 @@ func produceDefConflictError(conflictDefs map[string]string) error {
// checkBondComponentExistt will check the ready-to-apply object(def or auxiliary outputs) whether bind to a component
// if the target component not exist, return false.
func checkBondComponentExist(u unstructured.Unstructured, app v1beta1.Application) bool {
comp, existKey := u.GetAnnotations()[oam.AnnotationIgnoreWithoutCompKey]
var comp string
var existKey bool
comp, existKey = u.GetAnnotations()[oam.AnnotationAddonDefinitionBondCompKey]
if !existKey {
// if an object(def or auxiliary outputs ) binding no components return true
return true
// this is compatibility logic for deprecated annotation
comp, existKey = u.GetAnnotations()[oam.AnnotationIgnoreWithoutCompKey]
if !existKey {
// if an object(def or auxiliary outputs ) binding no components return true
return true
}
}
for _, component := range app.Spec.Components {
if component.Name == comp {

View File

@@ -290,10 +290,13 @@ func TestMakeChart(t *testing.T) {
func TestCheckObjectBindingComponent(t *testing.T) {
existingBindingDef := unstructured.Unstructured{}
existingBindingDef.SetAnnotations(map[string]string{oam.AnnotationIgnoreWithoutCompKey: "kustomize"})
existingBindingDef.SetAnnotations(map[string]string{oam.AnnotationAddonDefinitionBondCompKey: "kustomize"})
emptyAnnoDef := unstructured.Unstructured{}
emptyAnnoDef.SetAnnotations(map[string]string{"test": "onlyForTest"})
legacyAnnoDef := unstructured.Unstructured{}
legacyAnnoDef.SetAnnotations(map[string]string{oam.AnnotationIgnoreWithoutCompKey: "kustomize"})
testCases := map[string]struct {
object unstructured.Unstructured
app v1beta1.Application
@@ -311,6 +314,14 @@ func TestCheckObjectBindingComponent(t *testing.T) {
"EmptyApp": {object: existingBindingDef,
app: v1beta1.Application{Spec: v1beta1.ApplicationSpec{Components: []common.ApplicationComponent{}}},
res: false},
"LegacyApp": {object: legacyAnnoDef,
app: v1beta1.Application{Spec: v1beta1.ApplicationSpec{Components: []common.ApplicationComponent{{Name: "kustomize"}}}},
res: true,
},
"LegacyAppWithoutComp": {object: legacyAnnoDef,
app: v1beta1.Application{Spec: v1beta1.ApplicationSpec{Components: []common.ApplicationComponent{{}}}},
res: false,
},
}
for _, s := range testCases {
result := checkBondComponentExist(s.object, s.app)

View File

@@ -227,8 +227,12 @@ const (
// AnnotationResourceURL records the source url of the Kubernetes object
AnnotationResourceURL = "app.oam.dev/resource-url"
// AnnotationIgnoreWithoutCompKey indicates the bond component
// AnnotationIgnoreWithoutCompKey indicates the bond component.
// Deprecated: please use AnnotationAddonDefinitionBindCompKey.
AnnotationIgnoreWithoutCompKey = "addon.oam.dev/ignore-without-component"
// AnnotationAddonDefinitionBondCompKey indicates the definition in addon bond component.
AnnotationAddonDefinitionBondCompKey = "addon.oam.dev/bind-component"
)
const (