Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

[BUG] Can't find workloadDefinition is name was not match pattern <puraral-kind>.<resource-group> #207

Closed
wonderflow opened this issue Sep 16, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@wonderflow
Copy link
Member

Describe the bug

In #195 and #198 , we have created some workload definition have custom name.

When working with Definition like this. The controller can't work, it says can't find workloadDefinition as we don't follow the old convention that definition name will always equal to CRD name which match the pattern <puraral-kind>.<resource-group>

@wonderflow wonderflow added the bug Something isn't working label Sep 16, 2020
@zzxwill
Copy link
Member

zzxwill commented Sep 16, 2020

This happens when WorkloadDefinition's name doesn't follow the convention of <puraral-kind>.<resource-group>. For example.

  • WorkloadDefinition with name web-service
apiVersion: core.oam.dev/v1alpha2
kind: WorkloadDefinition
metadata:
  annotations:
    definition.oam.dev/name: web-service
  name: web-service
spec:
  definitionRef:
    name: containerizedworkloads.core.oam.dev
  childResourceKinds:
    - apiVersion: apps/v1
      kind: Deployment
    - apiVersion: v1
      kind: Service
  • component
apiVersion: core.oam.dev/v1alpha2
kind: Component
metadata:
  name: example-component
spec:
  workload:
    apiVersion: core.oam.dev/v1alpha2
    kind: ContainerizedWorkload
    metadata:
      annotations:
        definition.oam.dev/name: web-service
    spec:
      containers:
        - name: wordpress
          image: wordpress:4.6.1-apache
          ports:
            - containerPort: 80
              name: wordpress
          env:
            - name: TEST_ENV
              value: test
  parameters:
    - name: instance-name
      fieldPaths:
        - metadata.name
    - name: image
      fieldPaths:
        - spec.containers[0].image
  • ApplicationConfiguration
apiVersion: core.oam.dev/v1alpha2
kind: ApplicationConfiguration
metadata:
  name: example-appconfig
spec:
  components:
    - componentName: example-component
      parameterValues:
        - name: image
          value: wordpress:php7.2
      traits:
        - trait:
            apiVersion: core.oam.dev/v1alpha2
            kind: ManualScalerTrait
            metadata:
              name: example-appconfig-trait
            spec:
              replicaCount: 3

After these manifest are applied, it will hit the issue as below.

  Warning  failed to fetch workload child resources  4s (x2 over 5s)  ManualScalarTrait                          WorkloadDefinition.core.oam.dev "containerizedworkloads.core.oam.dev" not found

zzxwill added a commit to zzxwill/oam-kubernetes-runtime that referenced this issue Sep 16, 2020
When WorkloadDefinition doesn't follow the pattern
<puraral-kind>.<resource-group> or there are different
workloadDefinitions pointing to the same workload Schema,
it will hit the issue of could not finding workloaddefinition.
Fix issue crossplane#207, feature crossplane#195.

Signed-off-by: zzxwill <zzxwill@gmail.com>
@zzxwill
Copy link
Member

zzxwill commented Sep 16, 2020

Updated 2020.9.21, per comments from @ryanzhang-oss , using the annotation definition.oam.dev/name is abandoned. The existing label workload.oam.dev/type will be used as the marker.

Solution intro

After discussion with @wonderflow , here is the solution of draft PR #208

#195 requires users to add spec.workload.type to indicate the name of the WorkloadDefinition. Based on the mechanism, the web-hook can also set definition.oam.dev/name in annotation metadata.annotations for all workloads and the value is same as that of spec.workload.type.

The converted Component should be like as below.

apiVersion: core.oam.dev/v1alpha2
kind: Component
metadata:
  name: example-component
spec:
  workload:
    apiVersion: core.oam.dev/v1alpha2
    kind: ContainerizedWorkload
    metadata:
      annotations:
        definition.oam.dev/name: web-service

When reconciling, OAM runtime will first check whether there is a filed definition.oam.dev/name in annotations metadata.annotations, if yes, it will get the CRD name by it, or it will keep the previous way to retrieve the CRD name.

zzxwill added a commit to zzxwill/oam-kubernetes-runtime that referenced this issue Sep 17, 2020
When there is spec.type in Workload, an annotation will set for
the workload which can help find the WorkloadDefinition.

Fix issue crossplane#207, related to feature crossplane#195.

Co-authored-by: Sun Jianbo <wonderflow.sun@gmail.com>
Signed-off-by: zzxwill <zzxwill@gmail.com>
zzxwill added a commit to zzxwill/oam-kubernetes-runtime that referenced this issue Sep 18, 2020
When there is spec.type in Workload, an annotation will set for
the workload which can help find the WorkloadDefinition.

Fix issue crossplane#207, related to feature crossplane#195.

Co-authored-by: Sun Jianbo <wonderflow.sun@gmail.com>
Signed-off-by: zzxwill <zzxwill@gmail.com>
zzxwill added a commit to zzxwill/oam-kubernetes-runtime that referenced this issue Sep 18, 2020
When there is spec.type in Workload, an annotation will set for
the workload which can help find the WorkloadDefinition.

Fix issue crossplane#207, related to feature crossplane#195.

Co-authored-by: Sun Jianbo <wonderflow.sun@gmail.com>
Signed-off-by: zzxwill <zzxwill@gmail.com>
zzxwill added a commit to zzxwill/oam-kubernetes-runtime that referenced this issue Sep 21, 2020
When there is spec.type in Workload, an annotation will set for
the workload which can help find the WorkloadDefinition.

Fix issue crossplane#207, related to feature crossplane#195.

Co-authored-by: Sun Jianbo <wonderflow.sun@gmail.com>
Signed-off-by: zzxwill <zzxwill@gmail.com>
wonderflow added a commit that referenced this issue Sep 21, 2020
* Fix `could not find WorkloadDefinition` issue

When there is spec.type in Workload, an annotation will set for
the workload which can help find the WorkloadDefinition.

Fix issue #207, related to feature #195.

Co-authored-by: Sun Jianbo <wonderflow.sun@gmail.com>
Signed-off-by: zzxwill <zzxwill@gmail.com>

* Address comments and add unit-test

Signed-off-by: zzxwill <zzxwill@gmail.com>

* Fix goimports issue

Signed-off-by: zzxwill <zzxwill@gmail.com>

* Change function name and add unit-test

Signed-off-by: zzxwill <zzxwill@gmail.com>

* Removed maker annotation `definition.oam.dev/name`

Signed-off-by: zzxwill zzxwill@gmail.com
Signed-off-by: zzxwill <zzxwill@gmail.com>

Co-authored-by: Sun Jianbo <wonderflow.sun@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants