Skip to content

Commit

Permalink
Enables status subresource in order to fix generation bumping
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
dprotaso authored and bsnchan committed Apr 30, 2018
1 parent 646fe6b commit fda19f7
Show file tree
Hide file tree
Showing 25 changed files with 297 additions and 512 deletions.
2 changes: 2 additions & 0 deletions configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ spec:
kind: Configuration
plural: configurations
scope: Namespaced
subresources:
status: {}
14 changes: 0 additions & 14 deletions pkg/apis/ela/v1alpha1/configuration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ type Configuration struct {

// ConfigurationSpec holds the desired state of the Configuration (from the client).
type ConfigurationSpec struct {
// TODO: Generation does not work correctly with CRD. They are scrubbed
// by the APIserver (https://github.com/kubernetes/kubernetes/issues/58778)
// So, we add Generation here. Once that gets fixed, remove this and use
// ObjectMeta.Generation instead.
Generation int64 `json:"generation,omitempty"`

// Build optionally holds the specification for the build to
// perform to produce the Revision's container image.
Build *build.BuildSpec `json:"build,omitempty"`
Expand Down Expand Up @@ -122,14 +116,6 @@ type ConfigurationList struct {
Items []Configuration `json:"items"`
}

func (r *Configuration) GetGeneration() int64 {
return r.Spec.Generation
}

func (r *Configuration) SetGeneration(generation int64) {
r.Spec.Generation = generation
}

func (r *Configuration) GetSpecJSON() ([]byte, error) {
return json.Marshal(r.Spec)
}
Expand Down
12 changes: 0 additions & 12 deletions pkg/apis/ela/v1alpha1/configuration_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ import (
corev1 "k8s.io/api/core/v1"
)

func TestConfigurationGeneration(t *testing.T) {
config := Configuration{}
if e, a := int64(0), config.GetGeneration(); e != a {
t.Errorf("empty revision generation should be 0 was: %d", a)
}

config.SetGeneration(5)
if e, a := int64(5), config.GetGeneration(); e != a {
t.Errorf("getgeneration mismatch expected: %d got: %d", e, a)
}
}

func TestConfigurationIsReady(t *testing.T) {
cases := []struct {
name string
Expand Down
14 changes: 0 additions & 14 deletions pkg/apis/ela/v1alpha1/revision_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ const (

// RevisionSpec holds the desired state of the Revision (from the client).
type RevisionSpec struct {
// TODO: Generation does not work correctly with CRD. They are scrubbed
// by the APIserver (https://github.com/kubernetes/kubernetes/issues/58778)
// So, we add Generation here. Once that gets fixed, remove this and use
// ObjectMeta.Generation instead.
Generation int64 `json:"generation,omitempty"`

// ServingState holds a value describing the desired state the Kubernetes
// resources should be in for this Revision.
// Users must not specify this when creating a revision. It is expected
Expand Down Expand Up @@ -167,14 +161,6 @@ type RevisionList struct {
Items []Revision `json:"items"`
}

func (r *Revision) GetGeneration() int64 {
return r.Spec.Generation
}

func (r *Revision) SetGeneration(generation int64) {
r.Spec.Generation = generation
}

func (r *Revision) GetSpecJSON() ([]byte, error) {
return json.Marshal(r.Spec)
}
Expand Down
13 changes: 0 additions & 13 deletions pkg/apis/ela/v1alpha1/revision_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,6 @@ import (
corev1 "k8s.io/api/core/v1"
)

func TestGeneration(t *testing.T) {
r := Revision{}
if a := r.GetGeneration(); a != 0 {
t.Errorf("empty revision generation should be 0 was: %d", a)
}

r.SetGeneration(5)
if e, a := int64(5), r.GetGeneration(); e != a {
t.Errorf("getgeneration mismatch expected: %d got: %d", e, a)
}

}

func TestIsReady(t *testing.T) {
cases := []struct {
name string
Expand Down
14 changes: 0 additions & 14 deletions pkg/apis/ela/v1alpha1/route_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ type TrafficTarget struct {

// RouteSpec holds the desired state of the Route (from the client).
type RouteSpec struct {
// TODO: Generation does not work correctly with CRD. They are scrubbed
// by the APIserver (https://github.com/kubernetes/kubernetes/issues/58778)
// So, we add Generation here. Once that gets fixed, remove this and use
// ObjectMeta.Generation instead.
Generation int64 `json:"generation,omitempty"`

// Traffic specifies how to distribute traffic over a collection of Elafros Revisions and Configurations.
Traffic []TrafficTarget `json:"traffic,omitempty"`
}
Expand Down Expand Up @@ -141,14 +135,6 @@ type RouteList struct {
Items []Route `json:"items"`
}

func (r *Route) GetGeneration() int64 {
return r.Spec.Generation
}

func (r *Route) SetGeneration(generation int64) {
r.Spec.Generation = generation
}

func (r *Route) GetSpecJSON() ([]byte, error) {
return json.Marshal(r.Spec)
}
Expand Down
16 changes: 1 addition & 15 deletions pkg/apis/ela/v1alpha1/service_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,8 @@ type Service struct {
}

// ServiceSpec represents the configuration for the Service object.
// Exactly one of its members (other than Generation) must be specified.
// Exactly one of its members must be specified.
type ServiceSpec struct {
// TODO: Generation does not work correctly with CRD. They are scrubbed
// by the APIserver (https://github.com/kubernetes/kubernetes/issues/58778)
// So, we add Generation here. Once that gets fixed, remove this and use
// ObjectMeta.Generation instead.
Generation int64 `json:"generation,omitempty"`

// RunLatest defines a simple Service. It will automatically
// configure a route that keeps the latest ready revision
// from the supplied configuration running.
Expand Down Expand Up @@ -108,14 +102,6 @@ type ServiceList struct {
Items []Service `json:"items"`
}

func (s *Service) GetGeneration() int64 {
return s.Spec.Generation
}

func (s *Service) SetGeneration(generation int64) {
s.Spec.Generation = generation
}

func (s *Service) GetSpecJSON() ([]byte, error) {
return json.Marshal(s.Spec)
}
Expand Down
Loading

0 comments on commit fda19f7

Please sign in to comment.