From 26a7c630458302f403d09181a8593135366497b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E5=85=83?= Date: Fri, 9 Oct 2020 15:34:29 +0800 Subject: [PATCH] add podSpecPath into workloadDefinition, fixes #233 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 天元 --- apis/core/v1alpha2/core_types.go | 13 ++-- .../crds/core.oam.dev_components.yaml | 1 + .../crds/core.oam.dev_traitdefinitions.yaml | 5 ++ design/one-pager-podspecable-workload.md | 76 +++++++++++++++++++ 4 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 design/one-pager-podspecable-workload.md diff --git a/apis/core/v1alpha2/core_types.go b/apis/core/v1alpha2/core_types.go index 55363073..54b080d9 100644 --- a/apis/core/v1alpha2/core_types.go +++ b/apis/core/v1alpha2/core_types.go @@ -97,6 +97,11 @@ type TraitDefinitionSpec struct { // +optional WorkloadRefPath string `json:"workloadRefPath,omitempty"` + // PodSpecPath indicates where/if this workload has K8s podSpec field + // if one workload has podSpec, trait can do lot's of assumption such as port, env, volume fields. + // +optional + PodSpecPath string `json:"podSpecPath,omitempty"` + // AppliesToWorkloads specifies the list of workload kinds this trait // applies to. Workload kinds are specified in kind.group/version format, // e.g. server.core.oam.dev/v1alpha2. Traits that omit this field apply to @@ -189,9 +194,7 @@ type ComponentParameter struct { // paths without a leading dot, for example 'spec.replicas'. FieldPaths []string `json:"fieldPaths"` - // TODO(negz): Use +kubebuilder:default marker to default Required to false - // once we're generating v1 CRDs. - + // +kubebuilder:default:=false // Required specifies whether or not a value for this parameter must be // supplied when authoring an ApplicationConfiguration. // +optional @@ -231,9 +234,7 @@ type ComponentStatus struct { // +optional LatestRevision *Revision `json:"latestRevision,omitempty"` - // TODO(negz): Maintain references to any ApplicationConfigurations that - // reference this component? Doing so would allow us to queue a reconcile - // for consuming ApplicationConfigurations when this Component changed. + // One Component should only be used by one AppConfig } // Revision has name and revision number diff --git a/charts/oam-kubernetes-runtime/crds/core.oam.dev_components.yaml b/charts/oam-kubernetes-runtime/crds/core.oam.dev_components.yaml index 2bcda26b..287a8e45 100644 --- a/charts/oam-kubernetes-runtime/crds/core.oam.dev_components.yaml +++ b/charts/oam-kubernetes-runtime/crds/core.oam.dev_components.yaml @@ -72,6 +72,7 @@ spec: will specify parameter values using this name. type: string required: + default: false description: Required specifies whether or not a value for this parameter must be supplied when authoring an ApplicationConfiguration. type: boolean diff --git a/charts/oam-kubernetes-runtime/crds/core.oam.dev_traitdefinitions.yaml b/charts/oam-kubernetes-runtime/crds/core.oam.dev_traitdefinitions.yaml index 626a571c..236f5c8e 100644 --- a/charts/oam-kubernetes-runtime/crds/core.oam.dev_traitdefinitions.yaml +++ b/charts/oam-kubernetes-runtime/crds/core.oam.dev_traitdefinitions.yaml @@ -69,6 +69,11 @@ spec: builders type: object x-kubernetes-preserve-unknown-fields: true + podSpecPath: + description: PodSpecPath indicates where/if this workload has K8s + podSpec field if one workload has podSpec, trait can do lot's of + assumption such as port, env, volume fields. + type: string revisionEnabled: description: Revision indicates whether a trait is aware of component revision diff --git a/design/one-pager-podspecable-workload.md b/design/one-pager-podspecable-workload.md new file mode 100644 index 00000000..73d06e86 --- /dev/null +++ b/design/one-pager-podspecable-workload.md @@ -0,0 +1,76 @@ +# Indicate Workload has PodSpec field + +- Owner: Jianbo Sun (@wonderflow) +- Date: 10/09/2020 +- Status: Implemented + +## Background + +Since we have added labels like [`workload.oam.dev/podspecable`](https://github.com/oam-dev/spec/blob/master/4.workload_definitions.md#labels) +into OAM Spec to indicate the workload will contain 'podSpec' in its spec. + +In most famous workload like `Deployment`, `StatefulSet`, `Job`, the `podSpec` field will always be `spec.template.spec`. +But it's hard to know which field is podSpec for K8s CRD. For example, we write a workload named [`PodSpecWorkload`](https://github.com/oam-dev/kubevela/blob/master/charts/vela-core/crds/standard.oam.dev_podspecworkloads.yaml). +It has `podSpec` in `spec.podSpec`, this is different with `spec.template.spec`. In this case, we need a field to indicate +which field is `podSpec`. + +## Proposal + +So I propose we add a field 'podSpecPath' and a label `workload.oam.dev/podspecable: true` into WorkloadDefinition. + +The 'podSpecPath' field and the label are both optional fields, they could have following behaviors: + +### No label and No `podSpecPath` field + +``` +apiVersion: core.oam.dev/v1alpha2 +kind: WorkloadDefinition +metadata: + name: webservice +spec: + definitionRef: + name: podspecworkloads.standard.oam.dev + ... +``` + +In this case, we can't do any podSpec assumption for this workload. + +### label specified with No `podSpecPath` field + +``` +apiVersion: core.oam.dev/v1alpha2 +kind: WorkloadDefinition +metadata: + name: webservice + labels: + workload.oam.dev/podspecable: true +spec: + definitionRef: + name: podspecworkloads.standard.oam.dev + ... +``` + +In this case, we will always regard `spec.template.spec` as the `podSpecPath`. +This will work for most famous workloads like K8s `Deployment`/`StatefulSet`/`Job` and many other CRD Objects like +`OpenKruise CloneSet`/`Knative Service`. + +### Has `podSpecPath` field + +``` +apiVersion: core.oam.dev/v1alpha2 +kind: WorkloadDefinition +metadata: + name: webservice + labels: + workload.oam.dev/podspecable: true +spec: + podSpecPath: "spec.podSpec" + definitionRef: + name: podspecworkloads.standard.oam.dev + ... +``` + +If the `podSpecPath` is specified, the `workload.oam.dev/podspecable: true` label will always be automatically added. + +In this case, trait can use `podSpecPath` to get the field of podSpec. +