Skip to content

Commit e3da9a8

Browse files
authored
Use proper v1.PodTemplateSpec (#725)
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
1 parent 5cd2dca commit e3da9a8

File tree

9 files changed

+94
-92
lines changed

9 files changed

+94
-92
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ $(GENERATED): go.mod $(CRD_TYPE_SOURCE)
3535
./hack/update-codegen.sh
3636

3737
$(GENERATED_CRDS): $(GENERATED) $(CRD_SOURCES)
38-
go tool controller-gen crd:crdVersions=v1,allowDangerousTypes=true paths=./pkg/apis/... output:crd:dir=docs
38+
go tool controller-gen crd:crdVersions=v1,allowDangerousTypes=true,generateEmbeddedObjectMeta=true paths=./pkg/apis/... output:crd:dir=docs
3939
go run hack/crd/trim.go < docs/zalando.org_stacksets.yaml > docs/stackset_crd.yaml
4040
go run hack/crd/trim.go < docs/zalando.org_stacks.yaml > docs/stack_crd.yaml
4141
rm docs/zalando.org_stacksets.yaml docs/zalando.org_stacks.yaml

cmd/e2e/basic_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import (
1414
apps "k8s.io/api/apps/v1"
1515
autoscalingv2 "k8s.io/api/autoscaling/v2"
1616
corev1 "k8s.io/api/core/v1"
17-
v1 "k8s.io/api/networking/v1"
17+
networkingv1 "k8s.io/api/networking/v1"
1818
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1919
"k8s.io/apimachinery/pkg/util/intstr"
2020
)
2121

2222
var (
23-
pathType = v1.PathTypeImplementationSpecific
23+
pathType = networkingv1.PathTypeImplementationSpecific
2424
testAnnotationsCreate = map[string]string{
2525
"user-test-annotation": "create",
2626
}
@@ -179,7 +179,7 @@ func (f *TestStacksetSpecFactory) Create(t *testing.T, stackVersion string) zv1.
179179
Spec: zv1.StackSpecTemplate{
180180
StackSpec: zv1.StackSpec{
181181
Replicas: pint32(f.replicas),
182-
PodTemplate: zv1.PodTemplateSpec{
182+
PodTemplate: corev1.PodTemplateSpec{
183183
Spec: skipperPod,
184184
},
185185
Service: &zv1.StackServiceSpec{
@@ -506,19 +506,19 @@ func verifyStackIngressSources(
506506
require.Contains(t, stackIngress.Annotations, k)
507507
require.Equal(t, v, stackIngress.Annotations[k])
508508
}
509-
stackIngressRules := make([]v1.IngressRule, 0, len(clusterDomains))
509+
stackIngressRules := make([]networkingv1.IngressRule, 0, len(clusterDomains))
510510
for _, domain := range domains {
511-
stackIngressRules = append(stackIngressRules, v1.IngressRule{
511+
stackIngressRules = append(stackIngressRules, networkingv1.IngressRule{
512512
Host: domain,
513-
IngressRuleValue: v1.IngressRuleValue{
514-
HTTP: &v1.HTTPIngressRuleValue{
515-
Paths: []v1.HTTPIngressPath{
513+
IngressRuleValue: networkingv1.IngressRuleValue{
514+
HTTP: &networkingv1.HTTPIngressRuleValue{
515+
Paths: []networkingv1.HTTPIngressPath{
516516
{
517517
PathType: &pathType,
518-
Backend: v1.IngressBackend{
519-
Service: &v1.IngressServiceBackend{
518+
Backend: networkingv1.IngressBackend{
519+
Service: &networkingv1.IngressServiceBackend{
520520
Name: stack.Name,
521-
Port: v1.ServiceBackendPort{
521+
Port: networkingv1.ServiceBackendPort{
522522
Number: 80,
523523
},
524524
},

controller/stackset_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ func TestCreateCurrentStack(t *testing.T) {
336336
Version: "v1",
337337
StackSpec: zv1.StackSpec{
338338
Replicas: &replicas,
339-
PodTemplate: zv1.PodTemplateSpec{
339+
PodTemplate: v1.PodTemplateSpec{
340340
Spec: v1.PodSpec{
341341
Containers: []v1.Container{
342342
{

docs/stack_crd.yaml

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -526,26 +526,26 @@ spec:
526526
description: PodTemplate describes the pods that will be created.
527527
properties:
528528
metadata:
529-
description: Object's metadata.
529+
description: |-
530+
Standard object's metadata.
531+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
530532
properties:
531533
annotations:
532534
additionalProperties:
533535
type: string
534-
description: |-
535-
Annotations is an unstructured key value map stored with a resource that may be
536-
set by external tools to store and retrieve arbitrary metadata. They are not
537-
queryable and should be preserved when modifying objects.
538-
More info: http://kubernetes.io/docs/user-guide/annotations
539536
type: object
537+
finalizers:
538+
items:
539+
type: string
540+
type: array
540541
labels:
541542
additionalProperties:
542543
type: string
543-
description: |-
544-
Map of string keys and values that can be used to organize and categorize
545-
(scope and select) objects. May match selectors of replication controllers
546-
and services.
547-
More info: http://kubernetes.io/docs/user-guide/labels
548544
type: object
545+
name:
546+
type: string
547+
namespace:
548+
type: string
549549
type: object
550550
spec:
551551
description: |-
@@ -1101,6 +1101,11 @@ spec:
11011101
type: object
11021102
x-kubernetes-map-type: atomic
11031103
namespaces:
1104+
description: |-
1105+
namespaces specifies a static list of namespace names that the term applies to.
1106+
The term is applied to the union of the namespaces listed in this field
1107+
and the ones selected by namespaceSelector.
1108+
null or empty namespaces list and null namespaceSelector means "this pod's namespace".
11041109
items:
11051110
type: string
11061111
type: array
@@ -6287,6 +6292,12 @@ spec:
62876292
properties:
62886293
name:
62896294
default: ""
6295+
description: |-
6296+
Name of the referent.
6297+
This field is effectively required, but due to backwards compatibility is
6298+
allowed to be empty. Instances of this type with an empty value here are
6299+
almost certainly wrong.
6300+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
62906301
type: string
62916302
type: object
62926303
x-kubernetes-map-type: atomic
@@ -6448,6 +6459,23 @@ spec:
64486459
May contain labels and annotations that will be copied into the PVC
64496460
when creating it. No other fields are allowed and will be rejected during
64506461
validation.
6462+
properties:
6463+
annotations:
6464+
additionalProperties:
6465+
type: string
6466+
type: object
6467+
finalizers:
6468+
items:
6469+
type: string
6470+
type: array
6471+
labels:
6472+
additionalProperties:
6473+
type: string
6474+
type: object
6475+
name:
6476+
type: string
6477+
namespace:
6478+
type: string
64516479
type: object
64526480
spec:
64536481
description: |-
@@ -7231,12 +7259,6 @@ spec:
72317259
properties:
72327260
name:
72337261
default: ""
7234-
description: |-
7235-
Name of the referent.
7236-
This field is effectively required, but due to backwards compatibility is
7237-
allowed to be empty. Instances of this type with an empty value here are
7238-
almost certainly wrong.
7239-
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
72407262
type: string
72417263
type: object
72427264
x-kubernetes-map-type: atomic
@@ -7390,12 +7412,6 @@ spec:
73907412
properties:
73917413
name:
73927414
default: ""
7393-
description: |-
7394-
Name of the referent.
7395-
This field is effectively required, but due to backwards compatibility is
7396-
allowed to be empty. Instances of this type with an empty value here are
7397-
almost certainly wrong.
7398-
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
73997415
type: string
74007416
type: object
74017417
x-kubernetes-map-type: atomic

docs/stackset_crd.yaml

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -738,26 +738,26 @@ spec:
738738
description: PodTemplate describes the pods that will be created.
739739
properties:
740740
metadata:
741-
description: Object's metadata.
741+
description: |-
742+
Standard object's metadata.
743+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
742744
properties:
743745
annotations:
744746
additionalProperties:
745747
type: string
746-
description: |-
747-
Annotations is an unstructured key value map stored with a resource that may be
748-
set by external tools to store and retrieve arbitrary metadata. They are not
749-
queryable and should be preserved when modifying objects.
750-
More info: http://kubernetes.io/docs/user-guide/annotations
751748
type: object
749+
finalizers:
750+
items:
751+
type: string
752+
type: array
752753
labels:
753754
additionalProperties:
754755
type: string
755-
description: |-
756-
Map of string keys and values that can be used to organize and categorize
757-
(scope and select) objects. May match selectors of replication controllers
758-
and services.
759-
More info: http://kubernetes.io/docs/user-guide/labels
760756
type: object
757+
name:
758+
type: string
759+
namespace:
760+
type: string
761761
type: object
762762
spec:
763763
description: |-
@@ -6694,6 +6694,23 @@ spec:
66946694
May contain labels and annotations that will be copied into the PVC
66956695
when creating it. No other fields are allowed and will be rejected during
66966696
validation.
6697+
properties:
6698+
annotations:
6699+
additionalProperties:
6700+
type: string
6701+
type: object
6702+
finalizers:
6703+
items:
6704+
type: string
6705+
type: array
6706+
labels:
6707+
additionalProperties:
6708+
type: string
6709+
type: object
6710+
name:
6711+
type: string
6712+
namespace:
6713+
type: string
66976714
type: object
66986715
spec:
66996716
description: |-

pkg/apis/zalando.org/v1/types.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -396,19 +396,6 @@ type Stack struct {
396396
Status StackStatus `json:"status"`
397397
}
398398

399-
// PodTemplateSpec describes the data a pod should have when created from a template
400-
// +k8s:deepcopy-gen=true
401-
type PodTemplateSpec struct {
402-
// Object's metadata.
403-
// +optional
404-
EmbeddedObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
405-
406-
// Specification of the desired behavior of the pod.
407-
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
408-
// +optional
409-
Spec v1.PodSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
410-
}
411-
412399
// StackSpec is the spec part of the Stack.
413400
// +k8s:deepcopy-gen=true
414401
type StackSpec struct {
@@ -426,7 +413,7 @@ type StackSpec struct {
426413
// container port and ingress backendport.
427414
Service *StackServiceSpec `json:"service,omitempty"`
428415
// PodTemplate describes the pods that will be created.
429-
PodTemplate PodTemplateSpec `json:"podTemplate"`
416+
PodTemplate v1.PodTemplateSpec `json:"podTemplate"`
430417

431418
Autoscaler *Autoscaler `json:"autoscaler,omitempty"`
432419

pkg/apis/zalando.org/v1/zz_generated.deepcopy.go

Lines changed: 0 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/core/stack_resources.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func (sc *StackContainer) GenerateDeployment() *appsv1.Deployment {
231231
strategy = stack.Spec.StackSpec.Strategy.DeepCopy()
232232
}
233233

234-
embeddedCopy := stack.Spec.StackSpec.PodTemplate.EmbeddedObjectMeta.DeepCopy()
234+
embeddedCopy := stack.Spec.StackSpec.PodTemplate.ObjectMeta.DeepCopy()
235235

236236
templateObjectMeta := metav1.ObjectMeta{
237237
Annotations: embeddedCopy.Annotations,

pkg/core/stack_resources_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func TestGetServicePorts(tt *testing.T) {
7272
stackSpec: zv1.StackSpecInternal{
7373
StackSpec: zv1.StackSpec{
7474
Service: nil,
75-
PodTemplate: zv1.PodTemplateSpec{
75+
PodTemplate: v1.PodTemplateSpec{
7676
Spec: v1.PodSpec{
7777
Containers: []v1.Container{
7878
{
@@ -115,7 +115,7 @@ func TestGetServicePorts(tt *testing.T) {
115115
stackSpec: zv1.StackSpecInternal{
116116
StackSpec: zv1.StackSpec{
117117
Service: nil,
118-
PodTemplate: zv1.PodTemplateSpec{
118+
PodTemplate: v1.PodTemplateSpec{
119119
Spec: v1.PodSpec{
120120
Containers: []v1.Container{
121121
{
@@ -145,7 +145,7 @@ func TestGetServicePorts(tt *testing.T) {
145145
stackSpec: zv1.StackSpecInternal{
146146
StackSpec: zv1.StackSpec{
147147
Service: nil,
148-
PodTemplate: zv1.PodTemplateSpec{
148+
PodTemplate: v1.PodTemplateSpec{
149149
Spec: v1.PodSpec{
150150
Containers: []v1.Container{
151151
{
@@ -176,7 +176,7 @@ func TestGetServicePorts(tt *testing.T) {
176176
stackSpec: zv1.StackSpecInternal{
177177
StackSpec: zv1.StackSpec{
178178
Service: nil,
179-
PodTemplate: zv1.PodTemplateSpec{
179+
PodTemplate: v1.PodTemplateSpec{
180180
Spec: v1.PodSpec{
181181
Containers: []v1.Container{
182182
{
@@ -217,7 +217,7 @@ func TestGetServicePorts(tt *testing.T) {
217217
},
218218
},
219219
},
220-
PodTemplate: zv1.PodTemplateSpec{
220+
PodTemplate: v1.PodTemplateSpec{
221221
Spec: v1.PodSpec{
222222
Containers: []v1.Container{
223223
{
@@ -1166,7 +1166,7 @@ func TestStackGenerateService(t *testing.T) {
11661166
Spec: zv1.StackSpecInternal{
11671167
StackSpec: zv1.StackSpec{
11681168
Service: nil,
1169-
PodTemplate: zv1.PodTemplateSpec{
1169+
PodTemplate: v1.PodTemplateSpec{
11701170
Spec: v1.PodSpec{
11711171
Containers: []v1.Container{
11721172
{
@@ -1415,8 +1415,8 @@ func TestStackGenerateDeployment(t *testing.T) {
14151415
StackSpec: zv1.StackSpec{
14161416
MinReadySeconds: tc.minReadySeconds,
14171417
Strategy: strategy,
1418-
PodTemplate: zv1.PodTemplateSpec{
1419-
EmbeddedObjectMeta: zv1.EmbeddedObjectMeta{
1418+
PodTemplate: v1.PodTemplateSpec{
1419+
ObjectMeta: metav1.ObjectMeta{
14201420
Labels: map[string]string{
14211421
"pod-label": "pod-foo",
14221422
},
@@ -1603,8 +1603,8 @@ func TestGenerateHPA(t *testing.T) {
16031603
},
16041604
} {
16051605
t.Run(tc.name, func(t *testing.T) {
1606-
podTemplate := zv1.PodTemplateSpec{
1607-
EmbeddedObjectMeta: zv1.EmbeddedObjectMeta{
1606+
podTemplate := v1.PodTemplateSpec{
1607+
ObjectMeta: metav1.ObjectMeta{
16081608
Labels: map[string]string{
16091609
"pod-label": "pod-foo",
16101610
},
@@ -1679,8 +1679,8 @@ func TestGenerateHPAToSegment(t *testing.T) {
16791679
ObjectMeta: testStackMeta,
16801680
Spec: zv1.StackSpecInternal{
16811681
StackSpec: zv1.StackSpec{
1682-
PodTemplate: zv1.PodTemplateSpec{
1683-
EmbeddedObjectMeta: zv1.EmbeddedObjectMeta{
1682+
PodTemplate: v1.PodTemplateSpec{
1683+
ObjectMeta: metav1.ObjectMeta{
16841684
Labels: map[string]string{
16851685
"pod-label": "pod-foo",
16861686
},

0 commit comments

Comments
 (0)