Skip to content

Commit

Permalink
Make gateway and sensor controllers backward compatible with deprecat…
Browse files Browse the repository at this point in the history
…ed specs (#633)
  • Loading branch information
whynowy authored May 1, 2020
1 parent fb46335 commit 5f2734b
Show file tree
Hide file tree
Showing 15 changed files with 290 additions and 11 deletions.
2 changes: 1 addition & 1 deletion api/event-source.html
Original file line number Diff line number Diff line change
Expand Up @@ -2649,5 +2649,5 @@ <h3 id="argoproj.io/v1alpha1.TLSConfig">TLSConfig
<hr/>
<p><em>
Generated with <code>gen-crd-api-reference-docs</code>
on git commit <code>5172d79</code>.
on git commit <code>fb46335</code>.
</em></p>
2 changes: 1 addition & 1 deletion api/event-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -5236,6 +5236,6 @@ ClientKeyPath refers the file path that contains client key.
<p>

<em> Generated with <code>gen-crd-api-reference-docs</code> on git
commit <code>5172d79</code>. </em>
commit <code>fb46335</code>. </em>

</p>
38 changes: 37 additions & 1 deletion api/gateway.html
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,24 @@ <h3 id="argoproj.io/v1alpha1.Service">Service
<p>The list of ports that are exposed by this service.</p>
</td>
</tr>
<tr>
<td>
<code>spec</code></br>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#servicespec-v1-core">
Kubernetes core/v1.ServiceSpec
</a>
</em>
</td>
<td>
<p>Spec holds the gateway service spec.
DEPRECATED: Use Ports to declare the ports to be exposed.</p>
<br/>
<br/>
<table>
</table>
</td>
</tr>
</tbody>
</table>
<h3 id="argoproj.io/v1alpha1.Subscribers">Subscribers
Expand Down Expand Up @@ -749,10 +767,28 @@ <h3 id="argoproj.io/v1alpha1.Template">Template
Optional: Defaults to empty. See type description for default values of each field.</p>
</td>
</tr>
<tr>
<td>
<code>spec</code></br>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#podspec-v1-core">
Kubernetes core/v1.PodSpec
</a>
</em>
</td>
<td>
<p>Spec holds the gateway deployment spec.
DEPRECATED: Use Container instead.</p>
<br/>
<br/>
<table>
</table>
</td>
</tr>
</tbody>
</table>
<hr/>
<p><em>
Generated with <code>gen-crd-api-reference-docs</code>
on git commit <code>5172d79</code>.
on git commit <code>fb46335</code>.
</em></p>
60 changes: 59 additions & 1 deletion api/gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,35 @@ The list of ports that are exposed by this service.

</tr>

<tr>

<td>

<code>spec</code></br> <em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#servicespec-v1-core">
Kubernetes core/v1.ServiceSpec </a> </em>

</td>

<td>

<p>

Spec holds the gateway service spec. DEPRECATED: Use Ports to declare
the ports to be exposed.

</p>

<br/> <br/>

<table>

</table>

</td>

</tr>

</tbody>

</table>
Expand Down Expand Up @@ -1491,6 +1520,35 @@ values of each field.

</tr>

<tr>

<td>

<code>spec</code></br> <em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#podspec-v1-core">
Kubernetes core/v1.PodSpec </a> </em>

</td>

<td>

<p>

Spec holds the gateway deployment spec. DEPRECATED: Use Container
instead.

</p>

<br/> <br/>

<table>

</table>

</td>

</tr>

</tbody>

</table>
Expand All @@ -1500,6 +1558,6 @@ values of each field.
<p>

<em> Generated with <code>gen-crd-api-reference-docs</code> on git
commit <code>5172d79</code>. </em>
commit <code>fb46335</code>. </em>

</p>
12 changes: 12 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,10 @@
"x-kubernetes-list-type": "map",
"x-kubernetes-patch-merge-key": "port",
"x-kubernetes-patch-strategy": "merge"
},
"spec": {
"description": "Spec holds the gateway service spec. DEPRECATED: Use Ports to declare the ports to be exposed.",
"$ref": "#/definitions/io.k8s.api.core.v1.ServiceSpec"
}
}
},
Expand Down Expand Up @@ -952,6 +956,10 @@
"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/",
"type": "string"
},
"spec": {
"description": "Spec holds the gateway deployment spec. DEPRECATED: Use Container instead.",
"$ref": "#/definitions/io.k8s.api.core.v1.PodSpec"
},
"volumes": {
"description": "Volumes is a list of volumes that can be mounted by containers in a workflow.",
"type": "array",
Expand Down Expand Up @@ -2090,6 +2098,10 @@
"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/",
"type": "string"
},
"spec": {
"description": "Spec holds the sensor deployment spec. DEPRECATED: Use Container instead.",
"$ref": "#/definitions/io.k8s.api.core.v1.PodSpec"
},
"volumes": {
"description": "Volumes is a list of volumes that can be mounted by containers in a workflow.",
"type": "array",
Expand Down
20 changes: 19 additions & 1 deletion api/sensor.html
Original file line number Diff line number Diff line change
Expand Up @@ -2855,6 +2855,24 @@ <h3 id="argoproj.io/v1alpha1.Template">Template
Optional: Defaults to empty. See type description for default values of each field.</p>
</td>
</tr>
<tr>
<td>
<code>spec</code></br>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#podspec-v1-core">
Kubernetes core/v1.PodSpec
</a>
</em>
</td>
<td>
<p>Spec holds the sensor deployment spec.
DEPRECATED: Use Container instead.</p>
<br/>
<br/>
<table>
</table>
</td>
</tr>
</tbody>
</table>
<h3 id="argoproj.io/v1alpha1.TimeFilter">TimeFilter
Expand Down Expand Up @@ -3450,5 +3468,5 @@ <h3 id="argoproj.io/v1alpha1.URLArtifact">URLArtifact
<hr/>
<p><em>
Generated with <code>gen-crd-api-reference-docs</code>
on git commit <code>5172d79</code>.
on git commit <code>fb46335</code>.
</em></p>
31 changes: 30 additions & 1 deletion api/sensor.md
Original file line number Diff line number Diff line change
Expand Up @@ -5665,6 +5665,35 @@ values of each field.

</tr>

<tr>

<td>

<code>spec</code></br> <em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.13/#podspec-v1-core">
Kubernetes core/v1.PodSpec </a> </em>

</td>

<td>

<p>

Spec holds the sensor deployment spec. DEPRECATED: Use Container
instead.

</p>

<br/> <br/>

<table>

</table>

</td>

</tr>

</tbody>

</table>
Expand Down Expand Up @@ -6855,6 +6884,6 @@ VerifyCert decides whether the connection is secure or not
<p>

<em> Generated with <code>gen-crd-api-reference-docs</code> on git
commit <code>5172d79</code>. </em>
commit <code>fb46335</code>. </em>

</p>
62 changes: 60 additions & 2 deletions controllers/gateway/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ import (

// buildServiceResource builds a new service that exposes gateway.
func (ctx *gatewayContext) buildServiceResource() (*corev1.Service, error) {
if ctx.gateway.Spec.Service == nil || len(ctx.gateway.Spec.Service.Ports) == 0 {
if ctx.gateway.Spec.Service == nil {
return nil, nil
}
if ctx.gateway.Spec.Service.Spec != nil {
// Deprecated spec, will be unsupported soon.
ctx.logger.WithField("name", ctx.gateway.Name).WithField("namespace", ctx.gateway.Namespace).Warn("spec.service.spec is DEPRECATED, it will be unsupported soon, please use spec.service.ports")
return ctx.buildLegacyServiceResource()
}
if len(ctx.gateway.Spec.Service.Ports) == 0 {
return nil, nil
}
labels := map[string]string{
Expand All @@ -57,7 +65,32 @@ func (ctx *gatewayContext) buildServiceResource() (*corev1.Service, error) {
return svc, nil
}

// buildLegacyServiceResource is deprecated, will be unsupported soon.
func (ctx *gatewayContext) buildLegacyServiceResource() (*corev1.Service, error) {
labels := map[string]string{
common.LabelObjectName: ctx.gateway.Name,
common.LabelGatewayName: ctx.gateway.Name,
}
svc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-gateway-svc", ctx.gateway.Name),
},
Spec: *ctx.gateway.Spec.Service.Spec,
}
svc.Spec.Selector = labels
if err := controllerscommon.SetObjectMeta(ctx.gateway, svc, v1alpha1.SchemaGroupVersionKind); err != nil {
return nil, err
}
return svc, nil
}

func (ctx *gatewayContext) makeDeploymentSpec() (*appv1.DeploymentSpec, error) {
// Deprecated spec, will be unsupported soon.
if ctx.gateway.Spec.Template.Spec != nil {
ctx.logger.WithField("name", ctx.gateway.Name).WithField("namespace", ctx.gateway.Namespace).Warn("spec.template.spec is DEPRECATED, it will be unsupported soon, please use spec.template.container")
return ctx.makeLegacyDeploymentSpec()
}

replicas := int32(ctx.gateway.Spec.Replica)
if replicas == 0 {
replicas = 1
Expand Down Expand Up @@ -100,7 +133,7 @@ func (ctx *gatewayContext) makeDeploymentSpec() (*appv1.DeploymentSpec, error) {
ImagePullPolicy: corev1.PullAlways,
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: apiresource.MustParse("50m"),
corev1.ResourceCPU: apiresource.MustParse("10m"),
corev1.ResourceMemory: apiresource.MustParse("64Mi"),
},
Limits: corev1.ResourceList{
Expand All @@ -118,6 +151,31 @@ func (ctx *gatewayContext) makeDeploymentSpec() (*appv1.DeploymentSpec, error) {
}, nil
}

// makeLegacyDeploymentSpec is deprecated, will be unsupported soon.
func (ctx *gatewayContext) makeLegacyDeploymentSpec() (*appv1.DeploymentSpec, error) {
replicas := int32(ctx.gateway.Spec.Replica)
if replicas == 0 {
replicas = 1
}
labels := map[string]string{
common.LabelGatewayName: ctx.gateway.Name,
common.LabelObjectName: ctx.gateway.Name,
}

return &appv1.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: labels,
},
Replicas: &replicas,
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
},
Spec: *ctx.gateway.Spec.Template.Spec,
},
}, nil
}

// buildDeploymentResource builds a deployment resource for the gateway
func (ctx *gatewayContext) buildDeploymentResource() (*appv1.Deployment, error) {
deploymentSpec, err := ctx.makeDeploymentSpec()
Expand Down
26 changes: 26 additions & 0 deletions controllers/sensor/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ func (ctx *sensorContext) serviceBuilder() (*corev1.Service, error) {
}

func (ctx *sensorContext) makeDeploymentSpec() appv1.DeploymentSpec {
// Deprecated spec, will be unsupported soon.
if ctx.sensor.Spec.Template.Spec != nil {
ctx.logger.WithField("name", ctx.sensor.Name).WithField("namespace", ctx.sensor.Namespace).Warn("spec.template.spec is DEPRECATED, it will be unsupported soon, please use spec.template.container")
return ctx.makeLegacyDeploymentSpec()
}

replicas := int32(1)
labels := map[string]string{
common.LabelObjectName: ctx.sensor.Name,
Expand Down Expand Up @@ -113,6 +119,26 @@ func (ctx *sensorContext) makeDeploymentSpec() appv1.DeploymentSpec {
}
}

// makeLegacyDeploymentSpec is deprecated, will be unsupported soon.
func (ctx *sensorContext) makeLegacyDeploymentSpec() appv1.DeploymentSpec {
replicas := int32(1)
labels := map[string]string{
common.LabelObjectName: ctx.sensor.Name,
}
return appv1.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: labels,
},
Replicas: &replicas,
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: labels,
},
Spec: *ctx.sensor.Spec.Template.Spec,
},
}
}

// deploymentBuilder builds the deployment specification for the sensor
func (ctx *sensorContext) deploymentBuilder() (*appv1.Deployment, error) {
deploymentSpec := ctx.makeDeploymentSpec()
Expand Down
Loading

0 comments on commit 5f2734b

Please sign in to comment.