crossplane / oam-kubernetes-runtime

A set of libraries for building OAM runtimes
Apache License 2.0
277 stars 80 forks source link

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

Open wonderflow opened 4 years ago

wonderflow commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

This may not be a strong scenario.

erdun commented 4 years ago

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