Skip to content

Commit

Permalink
Drop spec.generation support (#234)
Browse files Browse the repository at this point in the history
* Drop webhook logic to increment spec.generation

With Kubernetes 1.11+ metadata.generation now increments properly
when the status subresource is enabled on CRDs

For more details see: knative/serving#643

* Drop the generational duck type
  • Loading branch information
dprotaso authored and knative-prow-robot committed Feb 14, 2019
1 parent 829b886 commit 0183bf9
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 437 deletions.
34 changes: 18 additions & 16 deletions apis/duck/typed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func TestSimpleList(t *testing.T) {
AddToScheme(scheme)
duckv1alpha1.AddToScheme(scheme)

namespace, name := "foo", "bar"
var want int64 = 1234
namespace, name, want := "foo", "bar", "my_hostname"

// Despite the signature allowing `...runtime.Object`, this method
// will not work properly unless the passed objects are `unstructured.Unstructured`
client := fake.NewSimpleDynamicClient(scheme, &unstructured.Unstructured{
Expand All @@ -52,8 +52,10 @@ func TestSimpleList(t *testing.T) {
"namespace": namespace,
"name": name,
},
"spec": map[string]interface{}{
"generation": want,
"status": map[string]interface{}{
"address": map[string]interface{}{
"hostname": want,
},
},
},
})
Expand All @@ -63,7 +65,7 @@ func TestSimpleList(t *testing.T) {

tif := &duck.TypedInformerFactory{
Client: client,
Type: &duckv1alpha1.Generational{},
Type: &duckv1alpha1.AddressableType{},
ResyncPeriod: 1 * time.Second,
StopChannel: stopCh,
}
Expand All @@ -80,13 +82,13 @@ func TestSimpleList(t *testing.T) {
t.Fatalf("Get() = %v", err)
}

got, ok := elt.(*duckv1alpha1.Generational)
got, ok := elt.(*duckv1alpha1.AddressableType)
if !ok {
t.Fatalf("Get() = %T, wanted *duckv1alpha1.Generational", elt)
t.Fatalf("Get() = %T, wanted *duckv1alpha1.AddressableType", elt)
}

if want != int64(got.Spec.Generation) {
t.Errorf("Get().Spec.Generation = %v, wanted %v", got.Spec.Generation, want)
if gotHostname := got.Status.Address.Hostname; gotHostname != want {
t.Errorf("Get().Status.Address.Hostname = %v, wanted %v", gotHostname, want)
}

// TODO(mattmoor): Access through informer
Expand All @@ -98,7 +100,7 @@ func TestAsStructuredWatcherNestedError(t *testing.T) {
return nil, want
}

wf := duck.AsStructuredWatcher(nwf, &duckv1alpha1.Generational{})
wf := duck.AsStructuredWatcher(nwf, &duckv1alpha1.AddressableType{})

_, got := wf(metav1.ListOptions{})
if got != want {
Expand All @@ -111,7 +113,7 @@ func TestAsStructuredWatcherClosedChannel(t *testing.T) {
return watch.NewEmptyWatch(), nil
}

wf := duck.AsStructuredWatcher(nwf, &duckv1alpha1.Generational{})
wf := duck.AsStructuredWatcher(nwf, &duckv1alpha1.AddressableType{})

wi, err := wf(metav1.ListOptions{})
if err != nil {
Expand All @@ -132,7 +134,7 @@ func TestAsStructuredWatcherPassThru(t *testing.T) {
return duck.NewProxyWatcher(unstructuredCh), nil
}

wf := duck.AsStructuredWatcher(nwf, &duckv1alpha1.Generational{})
wf := duck.AsStructuredWatcher(nwf, &duckv1alpha1.AddressableType{})

wi, err := wf(metav1.ListOptions{})
if err != nil {
Expand All @@ -159,13 +161,13 @@ func TestAsStructuredWatcherPassThru(t *testing.T) {
select {
case x, ok := <-ch:
if !ok {
t.Fatal("<-ch = closed, wanted *duckv1alpha1.Generational{}")
t.Fatal("<-ch = closed, wanted *duckv1alpha1.AddressableType{}")
}
if got := x.Type; got != want {
t.Errorf("x.Type = %v, wanted %v", got, want)
}
if _, ok := x.Object.(*duckv1alpha1.Generational); !ok {
t.Errorf("<-ch = %T, wanted %T", x, &duckv1alpha1.Generational{})
if _, ok := x.Object.(*duckv1alpha1.AddressableType); !ok {
t.Errorf("<-ch = %T, wanted %T", x, &duckv1alpha1.AddressableType{})
}
case <-time.After(100 * time.Millisecond):
t.Error("Didn't see expected message on channel.")
Expand All @@ -178,7 +180,7 @@ func TestAsStructuredWatcherPassThruErrors(t *testing.T) {
return duck.NewProxyWatcher(unstructuredCh), nil
}

wf := duck.AsStructuredWatcher(nwf, &duckv1alpha1.Generational{})
wf := duck.AsStructuredWatcher(nwf, &duckv1alpha1.AddressableType{})

wi, err := wf(metav1.ListOptions{})
if err != nil {
Expand Down
82 changes: 0 additions & 82 deletions apis/duck/v1alpha1/generational_types.go

This file was deleted.

2 changes: 0 additions & 2 deletions apis/duck/v1alpha1/implements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ import (
)

func TestTypesImplements(t *testing.T) {
var emptyGen Generation
testCases := []struct {
instance interface{}
iface duck.Implementable
}{
{instance: &AddressableType{}, iface: &Addressable{}},
{instance: &KResource{}, iface: &Conditions{}},
{instance: &Generational{}, iface: &emptyGen},
{instance: &LegacyTarget{}, iface: &LegacyTargetable{}},
{instance: &Target{}, iface: &Targetable{}},
}
Expand Down
2 changes: 0 additions & 2 deletions apis/duck/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ func addKnownTypes(scheme *runtime.Scheme) error {
SchemeGroupVersion,
&KResource{},
(&KResource{}).GetListType(),
&Generational{},
(&Generational{}).GetListType(),
&AddressableType{},
(&AddressableType{}).GetListType(),
&Target{},
Expand Down
76 changes: 0 additions & 76 deletions apis/duck/v1alpha1/zz_generated.deepcopy.go

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

3 changes: 0 additions & 3 deletions testing/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ var _ apis.Annotatable = (*Resource)(nil)
var _ apis.Listable = (*Resource)(nil)

// ResourceSpec represents test resource spec.
// TODO: Check that we implement the Generation duck type.
type ResourceSpec struct {
Generation int64 `json:"generation,omitempty"`

FieldWithDefault string `json:"fieldWithDefault,omitempty"`
FieldWithValidation string `json:"fieldWithValidation,omitempty"`
FieldThatsImmutable string `json:"fieldThatsImmutable,omitempty"`
Expand Down
31 changes: 0 additions & 31 deletions testing/resource_test.go

This file was deleted.

Loading

0 comments on commit 0183bf9

Please sign in to comment.