diff --git a/README.md b/README.md index 59efdf28..c4df4ab6 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ Or you can install with webhook enabled by following steps: kubectl -n oam-system create secret generic webhook-server-cert --from-file=tls.key=./oam-kubernetes-runtime-webhook.key --from-file=tls.crt=./oam-kubernetes-runtime-webhook.pem ``` - - Step 3: Get CA Bundle info and install with it's value + - Step 3: Get CA Bundle info and install with its value ```shell script caValue=`kubectl config view --raw --minify --flatten -o jsonpath='{.clusters[].cluster.certificate-authority-data}'` diff --git a/pkg/oam/util/helper.go b/pkg/oam/util/helper.go index 3238a853..5c19f8df 100644 --- a/pkg/oam/util/helper.go +++ b/pkg/oam/util/helper.go @@ -39,6 +39,9 @@ var ( const ( // TraitPrefixKey is prefix of trait name TraitPrefixKey = "trait" + // DefinitionAnnotation is one automatically generated annotation of workload and trait to indicate which + //workloadDefinition/traitDefinition it is generated by + DefinitionAnnotation = "definition.oam.dev/name" ) const ( @@ -226,7 +229,13 @@ func PassLabelAndAnnotation(parentObj oam.Object, childObj labelAnnotationObject // GetCRDName return the CRD name of any resources // the format of the CRD of a resource is . +// Now the CRD name of a resource could also be defined as `definition.oam.dev/name` in `metadata.annotations` func GetCRDName(u *unstructured.Unstructured) string { + if annotations := u.GetAnnotations(); annotations != nil { + if crdName, ok := annotations[DefinitionAnnotation]; ok { + return crdName + } + } group, _ := APIVersion2GroupVersion(u.GetAPIVersion()) resources := []string{Kind2Resource(u.GetKind())} if group != "" { diff --git a/pkg/webhook/v1alpha2/applicationconfiguration/applicationconfiguration.go b/pkg/webhook/v1alpha2/applicationconfiguration/applicationconfiguration.go index 8dbcdd73..c2e7129d 100644 --- a/pkg/webhook/v1alpha2/applicationconfiguration/applicationconfiguration.go +++ b/pkg/webhook/v1alpha2/applicationconfiguration/applicationconfiguration.go @@ -136,7 +136,7 @@ func (h *ValidatingHandler) InjectDecoder(d *admission.Decoder) error { return nil } -// Register will regsiter application configuration validation to webhook +// Register will register application configuration validation to webhook func Register(mgr manager.Manager) { server := mgr.GetWebhookServer() server.Register("/validating-core-oam-dev-v1alpha2-applicationconfigurations", &webhook.Admission{Handler: &ValidatingHandler{}}) diff --git a/pkg/webhook/v1alpha2/component/mutating_handler.go b/pkg/webhook/v1alpha2/component/mutating_handler.go index 8068dd1c..c6b24e59 100644 --- a/pkg/webhook/v1alpha2/component/mutating_handler.go +++ b/pkg/webhook/v1alpha2/component/mutating_handler.go @@ -125,7 +125,9 @@ func (h *MutatingHandler) Mutate(obj *v1alpha2.Component) error { // copy namespace/label/annotation to the workload and add workloadType label workload.SetNamespace(obj.GetNamespace()) workload.SetLabels(util.MergeMap(obj.GetLabels(), map[string]string{WorkloadTypeLabel: workloadType})) - workload.SetAnnotations(obj.GetAnnotations()) + // Add another annotation DefinitionAnnotation which can mark the name of WorkloadDefinition + workload.SetAnnotations(util.MergeMap(obj.GetAnnotations(), map[string]string{util.DefinitionAnnotation: workloadType})) + mutatelog.Info("Set annotation definition.oam.dev/name for workload", "annotation value", workloadType) // copy back the object rawBye, err := json.Marshal(workload.Object) if err != nil {