Skip to content

Commit

Permalink
fix: template metadata populated to gateway pod (#669)
Browse files Browse the repository at this point in the history
  • Loading branch information
whynowy authored May 20, 2020
1 parent ac90267 commit 0994043
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 10 deletions.
52 changes: 52 additions & 0 deletions api/gateway.html
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,45 @@ <h3 id="argoproj.io/v1alpha1.GatewayStatus">GatewayStatus
</tr>
</tbody>
</table>
<h3 id="argoproj.io/v1alpha1.Metadata">Metadata
</h3>
<p>
(<em>Appears on:</em>
<a href="#argoproj.io/v1alpha1.Template">Template</a>)
</p>
<p>
<p>Metadata holds the annotations and labels of a gateway pod</p>
</p>
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>annotations</code></br>
<em>
map[string]string
</em>
</td>
<td>
</td>
</tr>
<tr>
<td>
<code>labels</code></br>
<em>
map[string]string
</em>
</td>
<td>
</td>
</tr>
</tbody>
</table>
<h3 id="argoproj.io/v1alpha1.NATSSubscriber">NATSSubscriber
</h3>
<p>
Expand Down Expand Up @@ -731,6 +770,19 @@ <h3 id="argoproj.io/v1alpha1.Template">Template
<tbody>
<tr>
<td>
<code>metadata</code></br>
<em>
<a href="#argoproj.io/v1alpha1.Metadata">
Metadata
</a>
</em>
</td>
<td>
<p>Metdata sets the pods&rsquo;s metadata, i.e. annotations and labels</p>
</td>
</tr>
<tr>
<td>
<code>serviceAccountName</code></br>
<em>
string
Expand Down
100 changes: 100 additions & 0 deletions api/gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,85 @@ Resources refers to the metadata about the gateway resources

</table>

<h3 id="argoproj.io/v1alpha1.Metadata">

Metadata

</h3>

<p>

(<em>Appears on:</em>
<a href="#argoproj.io/v1alpha1.Template">Template</a>)

</p>

<p>

<p>

Metadata holds the annotations and labels of a gateway pod

</p>

</p>

<table>

<thead>

<tr>

<th>

Field

</th>

<th>

Description

</th>

</tr>

</thead>

<tbody>

<tr>

<td>

<code>annotations</code></br> <em> map\[string\]string </em>

</td>

<td>

</td>

</tr>

<tr>

<td>

<code>labels</code></br> <em> map\[string\]string </em>

</td>

<td>

</td>

</tr>

</tbody>

</table>

<h3 id="argoproj.io/v1alpha1.NATSSubscriber">

NATSSubscriber
Expand Down Expand Up @@ -1454,6 +1533,27 @@ Description

<td>

<code>metadata</code></br> <em>
<a href="#argoproj.io/v1alpha1.Metadata"> Metadata </a> </em>

</td>

<td>

<p>

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

</p>

</td>

</tr>

<tr>

<td>

<code>serviceAccountName</code></br> <em> string </em>

</td>
Expand Down
22 changes: 22 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down
20 changes: 18 additions & 2 deletions controllers/gateway/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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{
Expand All @@ -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,
},
Expand Down
50 changes: 49 additions & 1 deletion pkg/apis/gateway/v1alpha1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 15 additions & 7 deletions pkg/apis/gateway/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 0994043

Please sign in to comment.