Skip to content

Commit fda19f7

Browse files
dprotasobsnchan
authored andcommitted
Enables status subresource in order to fix generation bumping
* This requires k8s 1.10 with CustomResourceSubresources feature gate enabled * Patching is used instead of update when adding labels - prevents bumping the generation since nested specs have a k8s Time struct which, during serialization, are not omitted when empty #642 Signed-off-by: Brenda Chan <brchan@pivotal.io>
1 parent 646fe6b commit fda19f7

25 files changed

+297
-512
lines changed

configuration.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ spec:
2323
kind: Configuration
2424
plural: configurations
2525
scope: Namespaced
26+
subresources:
27+
status: {}

pkg/apis/ela/v1alpha1/configuration_types.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ type Configuration struct {
4747

4848
// ConfigurationSpec holds the desired state of the Configuration (from the client).
4949
type ConfigurationSpec struct {
50-
// TODO: Generation does not work correctly with CRD. They are scrubbed
51-
// by the APIserver (https://github.com/kubernetes/kubernetes/issues/58778)
52-
// So, we add Generation here. Once that gets fixed, remove this and use
53-
// ObjectMeta.Generation instead.
54-
Generation int64 `json:"generation,omitempty"`
55-
5650
// Build optionally holds the specification for the build to
5751
// perform to produce the Revision's container image.
5852
Build *build.BuildSpec `json:"build,omitempty"`
@@ -122,14 +116,6 @@ type ConfigurationList struct {
122116
Items []Configuration `json:"items"`
123117
}
124118

125-
func (r *Configuration) GetGeneration() int64 {
126-
return r.Spec.Generation
127-
}
128-
129-
func (r *Configuration) SetGeneration(generation int64) {
130-
r.Spec.Generation = generation
131-
}
132-
133119
func (r *Configuration) GetSpecJSON() ([]byte, error) {
134120
return json.Marshal(r.Spec)
135121
}

pkg/apis/ela/v1alpha1/configuration_types_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@ import (
1818
corev1 "k8s.io/api/core/v1"
1919
)
2020

21-
func TestConfigurationGeneration(t *testing.T) {
22-
config := Configuration{}
23-
if e, a := int64(0), config.GetGeneration(); e != a {
24-
t.Errorf("empty revision generation should be 0 was: %d", a)
25-
}
26-
27-
config.SetGeneration(5)
28-
if e, a := int64(5), config.GetGeneration(); e != a {
29-
t.Errorf("getgeneration mismatch expected: %d got: %d", e, a)
30-
}
31-
}
32-
3321
func TestConfigurationIsReady(t *testing.T) {
3422
cases := []struct {
3523
name string

pkg/apis/ela/v1alpha1/revision_types.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ const (
7070

7171
// RevisionSpec holds the desired state of the Revision (from the client).
7272
type RevisionSpec struct {
73-
// TODO: Generation does not work correctly with CRD. They are scrubbed
74-
// by the APIserver (https://github.com/kubernetes/kubernetes/issues/58778)
75-
// So, we add Generation here. Once that gets fixed, remove this and use
76-
// ObjectMeta.Generation instead.
77-
Generation int64 `json:"generation,omitempty"`
78-
7973
// ServingState holds a value describing the desired state the Kubernetes
8074
// resources should be in for this Revision.
8175
// Users must not specify this when creating a revision. It is expected
@@ -167,14 +161,6 @@ type RevisionList struct {
167161
Items []Revision `json:"items"`
168162
}
169163

170-
func (r *Revision) GetGeneration() int64 {
171-
return r.Spec.Generation
172-
}
173-
174-
func (r *Revision) SetGeneration(generation int64) {
175-
r.Spec.Generation = generation
176-
}
177-
178164
func (r *Revision) GetSpecJSON() ([]byte, error) {
179165
return json.Marshal(r.Spec)
180166
}

pkg/apis/ela/v1alpha1/revision_types_test.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,6 @@ import (
1919
corev1 "k8s.io/api/core/v1"
2020
)
2121

22-
func TestGeneration(t *testing.T) {
23-
r := Revision{}
24-
if a := r.GetGeneration(); a != 0 {
25-
t.Errorf("empty revision generation should be 0 was: %d", a)
26-
}
27-
28-
r.SetGeneration(5)
29-
if e, a := int64(5), r.GetGeneration(); e != a {
30-
t.Errorf("getgeneration mismatch expected: %d got: %d", e, a)
31-
}
32-
33-
}
34-
3522
func TestIsReady(t *testing.T) {
3623
cases := []struct {
3724
name string

pkg/apis/ela/v1alpha1/route_types.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ type TrafficTarget struct {
7171

7272
// RouteSpec holds the desired state of the Route (from the client).
7373
type RouteSpec struct {
74-
// TODO: Generation does not work correctly with CRD. They are scrubbed
75-
// by the APIserver (https://github.com/kubernetes/kubernetes/issues/58778)
76-
// So, we add Generation here. Once that gets fixed, remove this and use
77-
// ObjectMeta.Generation instead.
78-
Generation int64 `json:"generation,omitempty"`
79-
8074
// Traffic specifies how to distribute traffic over a collection of Elafros Revisions and Configurations.
8175
Traffic []TrafficTarget `json:"traffic,omitempty"`
8276
}
@@ -141,14 +135,6 @@ type RouteList struct {
141135
Items []Route `json:"items"`
142136
}
143137

144-
func (r *Route) GetGeneration() int64 {
145-
return r.Spec.Generation
146-
}
147-
148-
func (r *Route) SetGeneration(generation int64) {
149-
r.Spec.Generation = generation
150-
}
151-
152138
func (r *Route) GetSpecJSON() ([]byte, error) {
153139
return json.Marshal(r.Spec)
154140
}

pkg/apis/ela/v1alpha1/service_types.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,8 @@ type Service struct {
3636
}
3737

3838
// ServiceSpec represents the configuration for the Service object.
39-
// Exactly one of its members (other than Generation) must be specified.
39+
// Exactly one of its members must be specified.
4040
type ServiceSpec struct {
41-
// TODO: Generation does not work correctly with CRD. They are scrubbed
42-
// by the APIserver (https://github.com/kubernetes/kubernetes/issues/58778)
43-
// So, we add Generation here. Once that gets fixed, remove this and use
44-
// ObjectMeta.Generation instead.
45-
Generation int64 `json:"generation,omitempty"`
46-
4741
// RunLatest defines a simple Service. It will automatically
4842
// configure a route that keeps the latest ready revision
4943
// from the supplied configuration running.
@@ -108,14 +102,6 @@ type ServiceList struct {
108102
Items []Service `json:"items"`
109103
}
110104

111-
func (s *Service) GetGeneration() int64 {
112-
return s.Spec.Generation
113-
}
114-
115-
func (s *Service) SetGeneration(generation int64) {
116-
s.Spec.Generation = generation
117-
}
118-
119105
func (s *Service) GetSpecJSON() ([]byte, error) {
120106
return json.Marshal(s.Spec)
121107
}

0 commit comments

Comments
 (0)