[go: nahoru, domu]

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

using strategy merge patch for update if trait/workload is K8s built-in resource #83

Open
wonderflow opened this issue Jul 6, 2020 · 3 comments

Comments

@wonderflow
Copy link
Member
wonderflow commented Jul 6, 2020

K8s has strategic merge patch, this is useful for update. If OAM workload/trait is k8s built-in resource, for example(deloyment, ingress),then we should use strategy merge patch.

Write this issue for @CoderPoet

@CoderPoet
Copy link

Here is a scenario case

I described and published an application through oam, as follows

apiVersion: core.oam.dev/v1alpha2
kind: Component
metadata:
  name: stateless-example-component
  namespace: oam-sample
spec:
  workload:
    apiVersion: core.matrix.io/v1alpha1
    kind: StatelessWorkload
    spec:
      serviceName: statelessworkload-nginx
      template:
        spec:
          containers:
            - name: container-nginx
              image: noop
              ports:
                - name: http
                  containerPort: 80
                  protocol: TCP
  parameters:
    - name: instance-name
      required: true
      fieldPaths:
        - metadata.name
    - name: image
      fieldPaths:
        - spec.template.spec.containers[0].image
----
apiVersion: core.oam.dev/v1alpha2
kind: ApplicationConfiguration
metadata:
  name: stateless-example-appconfig
  namespace: oam-sample
spec:
  components:
    - componentName: stateless-example-component
      parameterValues:
        - name: instance-name
          value: statelessworkload-nginx
        - name: image
          value: nginx
      traits:
        - trait:
            apiVersion: networking.istio.io/v1beta1
            kind: VirtualService
            metadata:
              name: statelessworkload-nginx
              namespace: oam-sample
            spec:
              gateways:
                - istio-system/common-gateway
              hosts:
                - statelessworkload-nginx.sk8s.cn
              http:
                - route:
                    - destination:
                        host: statelessworkload-nginx.oam-sample.svc.cluster.local
                      weight: 100
        - trait:
            apiVersion: core.oam.dev/v1alpha2
            kind: ManualScalerTrait
            metadata:
              name: example-stateless-trait
            spec:
              replicaCount: 2

Then I directly modified some fields of VirtualService resources (fields not touched by OAM) through other channels

For example, add a CORS strategy on a platform that I have not yet migrated to OAM

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  creationTimestamp: '2020-07-04T10:11:09Z'
  generation: 9
  name: statelessworkload-nginx
  namespace: oam-sample
  ownerReferences:
    - apiVersion: core.oam.dev/v1alpha2
      blockOwnerDeletion: true
      controller: true
      kind: ApplicationConfiguration
      name: stateless-example-appconfig
      uid: 67c65fc2-f090-4398-9d7b-cf376307d72c
spec:
  gateways:
    - istio-system/common-gateway
  hosts:
    - statelessworkload-nginx.sk8s.cn
  http:
    - corsPolicy:
        allowCredentials: true
        allowHeaders:
          - '*'
        allowMethods:
          - POST
          - PUT
          - PATCH
        allowOrigin:
          - '*'
      route:
        - destination:
            host: statelessworkload-nginx.oam-sample.svc.cluster.local
          weight: 100

At this time, oam runtime will ignore my changes and change to the state described in appconfig, mainly because strategy merge patch is not used

@wonderflow
Copy link
Member Author

This may not be a strong scenario.

@erdun
Copy link
Contributor
erdun commented Jul 6, 2020

Trait/workload are generate by oam server and don't edit by kubectl, so using patch. But updating k8s built-in resource like deployment in containerizedworkload should use strategy merge patch

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants