diff --git a/api/gateway.html b/api/gateway.html index f5ad15edec..185cb7d324 100644 --- a/api/gateway.html +++ b/api/gateway.html @@ -434,6 +434,45 @@

GatewayStatus +

Metadata +

+

+(Appears on: +Template) +

+

+

Metadata holds the annotations and labels of a gateway pod

+

+ + + + + + + + + + + + + + + + + +
FieldDescription
+annotations
+ +map[string]string + +
+
+labels
+ +map[string]string + +
+

NATSSubscriber

@@ -731,6 +770,19 @@

Template +metadata
+ + +Metadata + + + + +

Metdata sets the pods’s metadata, i.e. annotations and labels

+ + + + serviceAccountName
string diff --git a/api/gateway.md b/api/gateway.md index ef025a6c5b..6eed94d7dd 100644 --- a/api/gateway.md +++ b/api/gateway.md @@ -846,6 +846,85 @@ Resources refers to the metadata about the gateway resources +

+ +Metadata + +

+ +

+ +(Appears on: +Template) + +

+ +

+ +

+ +Metadata holds the annotations and labels of a gateway pod + +

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +Field + + + +Description + +
+ +annotations
map\[string\]string + +
+ +
+ +labels
map\[string\]string + +
+ +
+

NATSSubscriber @@ -1454,6 +1533,27 @@ Description +metadata
+ Metadata + + + + + +

+ +Metdata sets the pods’s metadata, i.e. annotations and labels + +

+ + + + + + + + + serviceAccountName
string diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index 9223d0ccd5..946f8218e9 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -836,6 +836,24 @@ } } }, + "io.argoproj.gateway.v1alpha1.Metadata": { + "description": "Metadata holds the annotations and labels of a gateway pod", + "type": "object", + "properties": { + "annotations": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "labels": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + }, "io.argoproj.gateway.v1alpha1.NATSSubscriber": { "description": "NATSSubscriber holds the context of subscriber over NATS.", "type": "object", @@ -956,6 +974,10 @@ "description": "Container is the main container image to run in the gateway pod", "$ref": "#/definitions/io.k8s.api.core.v1.Container" }, + "metadata": { + "description": "Metdata sets the pods's metadata, i.e. annotations and labels", + "$ref": "#/definitions/io.argoproj.gateway.v1alpha1.Metadata" + }, "securityContext": { "description": "SecurityContext holds pod-level security attributes and common container settings. Optional: Defaults to empty. See type description for default values of each field.", "$ref": "#/definitions/io.k8s.api.core.v1.PodSecurityContext" diff --git a/controllers/gateway/resource.go b/controllers/gateway/resource.go index 448070af3f..fe20bc7622 100644 --- a/controllers/gateway/resource.go +++ b/controllers/gateway/resource.go @@ -101,6 +101,13 @@ func (ctx *gatewayContext) makeDeploymentSpec() (*appv1.DeploymentSpec, error) { common.LabelGatewayName: ctx.gateway.Name, common.LabelObjectName: ctx.gateway.Name, } + podTemplateLabels := make(map[string]string) + if len(ctx.gateway.Spec.Template.Metadata.Labels) > 0 { + podTemplateLabels = ctx.gateway.Spec.Template.Metadata.Labels + } + for k, v := range labels { + podTemplateLabels[k] = v + } eventContainer := corev1.Container{ Name: "main", @@ -123,7 +130,8 @@ func (ctx *gatewayContext) makeDeploymentSpec() (*appv1.DeploymentSpec, error) { Replicas: &replicas, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ - Labels: labels, + Labels: podTemplateLabels, + Annotations: ctx.gateway.Spec.Template.Metadata.Annotations, }, Spec: corev1.PodSpec{ ServiceAccountName: ctx.gateway.Spec.Template.ServiceAccountName, @@ -164,6 +172,13 @@ func (ctx *gatewayContext) makeLegacyDeploymentSpec() (*appv1.DeploymentSpec, er common.LabelGatewayName: ctx.gateway.Name, common.LabelObjectName: ctx.gateway.Name, } + podTemplateLabels := make(map[string]string) + if len(ctx.gateway.Spec.Template.Metadata.Labels) > 0 { + podTemplateLabels = ctx.gateway.Spec.Template.Metadata.Labels + } + for k, v := range labels { + podTemplateLabels[k] = v + } return &appv1.DeploymentSpec{ Selector: &metav1.LabelSelector{ @@ -172,7 +187,8 @@ func (ctx *gatewayContext) makeLegacyDeploymentSpec() (*appv1.DeploymentSpec, er Replicas: &replicas, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ - Labels: labels, + Labels: podTemplateLabels, + Annotations: ctx.gateway.Spec.Template.Metadata.Annotations, }, Spec: *ctx.gateway.Spec.Template.Spec, }, diff --git a/pkg/apis/gateway/v1alpha1/openapi_generated.go b/pkg/apis/gateway/v1alpha1/openapi_generated.go index 131d027f88..9d3bf7ca66 100644 --- a/pkg/apis/gateway/v1alpha1/openapi_generated.go +++ b/pkg/apis/gateway/v1alpha1/openapi_generated.go @@ -35,6 +35,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/argoproj/argo-events/pkg/apis/gateway/v1alpha1.GatewayResource": schema_pkg_apis_gateway_v1alpha1_GatewayResource(ref), "github.com/argoproj/argo-events/pkg/apis/gateway/v1alpha1.GatewaySpec": schema_pkg_apis_gateway_v1alpha1_GatewaySpec(ref), "github.com/argoproj/argo-events/pkg/apis/gateway/v1alpha1.GatewayStatus": schema_pkg_apis_gateway_v1alpha1_GatewayStatus(ref), + "github.com/argoproj/argo-events/pkg/apis/gateway/v1alpha1.Metadata": schema_pkg_apis_gateway_v1alpha1_Metadata(ref), "github.com/argoproj/argo-events/pkg/apis/gateway/v1alpha1.NATSSubscriber": schema_pkg_apis_gateway_v1alpha1_NATSSubscriber(ref), "github.com/argoproj/argo-events/pkg/apis/gateway/v1alpha1.NodeStatus": schema_pkg_apis_gateway_v1alpha1_NodeStatus(ref), "github.com/argoproj/argo-events/pkg/apis/gateway/v1alpha1.Service": schema_pkg_apis_gateway_v1alpha1_Service(ref), @@ -318,6 +319,47 @@ func schema_pkg_apis_gateway_v1alpha1_GatewayStatus(ref common.ReferenceCallback } } +func schema_pkg_apis_gateway_v1alpha1_Metadata(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Metadata holds the annotations and labels of a gateway pod", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "annotations": { + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + "labels": { + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + }, + }, + }, + } +} + func schema_pkg_apis_gateway_v1alpha1_NATSSubscriber(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -520,6 +562,12 @@ func schema_pkg_apis_gateway_v1alpha1_Template(ref common.ReferenceCallback) com Description: "Template holds the information of a Gateway deployment template", Type: []string{"object"}, Properties: map[string]spec.Schema{ + "metadata": { + SchemaProps: spec.SchemaProps{ + Description: "Metdata sets the pods's metadata, i.e. annotations and labels", + Ref: ref("github.com/argoproj/argo-events/pkg/apis/gateway/v1alpha1.Metadata"), + }, + }, "serviceAccountName": { SchemaProps: spec.SchemaProps{ Description: "ServiceAccountName is the name of the ServiceAccount to use to run gateway pod. More info: https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/", @@ -587,6 +635,6 @@ func schema_pkg_apis_gateway_v1alpha1_Template(ref common.ReferenceCallback) com }, }, Dependencies: []string{ - "k8s.io/api/core/v1.Affinity", "k8s.io/api/core/v1.Container", "k8s.io/api/core/v1.PodSecurityContext", "k8s.io/api/core/v1.PodSpec", "k8s.io/api/core/v1.Toleration", "k8s.io/api/core/v1.Volume"}, + "github.com/argoproj/argo-events/pkg/apis/gateway/v1alpha1.Metadata", "k8s.io/api/core/v1.Affinity", "k8s.io/api/core/v1.Container", "k8s.io/api/core/v1.PodSecurityContext", "k8s.io/api/core/v1.PodSpec", "k8s.io/api/core/v1.Toleration", "k8s.io/api/core/v1.Volume"}, } } diff --git a/pkg/apis/gateway/v1alpha1/types.go b/pkg/apis/gateway/v1alpha1/types.go index 84c9d9de87..c7f4b5efd6 100644 --- a/pkg/apis/gateway/v1alpha1/types.go +++ b/pkg/apis/gateway/v1alpha1/types.go @@ -78,31 +78,39 @@ type GatewaySpec struct { // Template holds the information of a Gateway deployment template type Template struct { + // Metdata sets the pods's metadata, i.e. annotations and labels + Metadata Metadata `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` // ServiceAccountName is the name of the ServiceAccount to use to run gateway pod. // More info: https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/ // +optional - ServiceAccountName string `json:"serviceAccountName,omitempty" protobuf:"bytes,1,opt,name=serviceAccountName"` + ServiceAccountName string `json:"serviceAccountName,omitempty" protobuf:"bytes,2,opt,name=serviceAccountName"` // Container is the main container image to run in the gateway pod // +optional - Container *corev1.Container `json:"container,omitempty" protobuf:"bytes,2,opt,name=container"` + Container *corev1.Container `json:"container,omitempty" protobuf:"bytes,3,opt,name=container"` // Volumes is a list of volumes that can be mounted by containers in a workflow. // +patchStrategy=merge // +patchMergeKey=name // +optional - Volumes []corev1.Volume `json:"volumes,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,3,opt,name=volumes"` + Volumes []corev1.Volume `json:"volumes,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,4,opt,name=volumes"` // SecurityContext holds pod-level security attributes and common container settings. // Optional: Defaults to empty. See type description for default values of each field. // +optional - SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty" protobuf:"bytes,4,opt,name=securityContext"` + SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty" protobuf:"bytes,5,opt,name=securityContext"` // If specified, the pod's scheduling constraints // +optional - Affinity *corev1.Affinity `json:"affinity,omitempty" protobuf:"bytes,5,opt,name=affinity"` + Affinity *corev1.Affinity `json:"affinity,omitempty" protobuf:"bytes,6,opt,name=affinity"` // If specified, the pod's tolerations. // +optional - Tolerations []corev1.Toleration `json:"tolerations,omitempty" protobuf:"bytes,6,opt,name=tolerations"` + Tolerations []corev1.Toleration `json:"tolerations,omitempty" protobuf:"bytes,7,opt,name=tolerations"` // Spec holds the gateway deployment spec. // DEPRECATED: Use Container instead. - Spec *corev1.PodSpec `json:"spec,omitempty" protobuf:"bytes,7,opt,name=spec"` + Spec *corev1.PodSpec `json:"spec,omitempty" protobuf:"bytes,8,opt,name=spec"` +} + +// Metadata holds the annotations and labels of a gateway pod +type Metadata struct { + Annotations map[string]string `json:"annotations,omitempty" protobuf:"bytes,1,opt,name=annotations"` + Labels map[string]string `json:"labels,omitempty" protobuf:"bytes,2,opt,name=labels"` } // Service holds the service information gateway exposes diff --git a/pkg/apis/gateway/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/gateway/v1alpha1/zz_generated.deepcopy.go index 927849bfd8..01f0c41ced 100644 --- a/pkg/apis/gateway/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/gateway/v1alpha1/zz_generated.deepcopy.go @@ -190,6 +190,36 @@ func (in *GatewayStatus) DeepCopy() *GatewayStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Metadata) DeepCopyInto(out *Metadata) { + *out = *in + if in.Annotations != nil { + in, out := &in.Annotations, &out.Annotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Labels != nil { + in, out := &in.Labels, &out.Labels + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Metadata. +func (in *Metadata) DeepCopy() *Metadata { + if in == nil { + return nil + } + out := new(Metadata) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NATSSubscriber) DeepCopyInto(out *NATSSubscriber) { *out = *in @@ -279,6 +309,7 @@ func (in *Subscribers) DeepCopy() *Subscribers { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Template) DeepCopyInto(out *Template) { *out = *in + in.Metadata.DeepCopyInto(&out.Metadata) if in.Container != nil { in, out := &in.Container, &out.Container *out = new(corev1.Container)