diff --git a/go.mod b/go.mod index 91be922e..a3b52246 100644 --- a/go.mod +++ b/go.mod @@ -21,5 +21,5 @@ require ( k8s.io/code-generator v0.21.4 k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7 knative.dev/hack v0.0.0-20210806075220-815cd312d65c - knative.dev/pkg v0.0.0-20210907232433-26db1ba732f6 + knative.dev/pkg v0.0.0-20210908025933-71508fc69a57 ) diff --git a/go.sum b/go.sum index abacad09..43f2fb0b 100644 --- a/go.sum +++ b/go.sum @@ -978,8 +978,8 @@ k8s.io/utils v0.0.0-20201110183641-67b214c5f920 h1:CbnUZsM497iRC5QMVkHwyl8s2tB3g k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= knative.dev/hack v0.0.0-20210806075220-815cd312d65c h1:nOXoDWAAItwr4o0dp3nHr6skgpVD4IvME/UX84YNl5k= knative.dev/hack v0.0.0-20210806075220-815cd312d65c/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI= -knative.dev/pkg v0.0.0-20210907232433-26db1ba732f6 h1:nLHaEQP+SNW4E6zsgSS6wwpHNpSpag8vw8SSsH4ILw8= -knative.dev/pkg v0.0.0-20210907232433-26db1ba732f6/go.mod h1:jMSqkNMsrzuy+XR4Yr/BMy7SDVbUOl3KKB6+5MR+ZU8= +knative.dev/pkg v0.0.0-20210908025933-71508fc69a57 h1:du+do3to2zboxuk0Uj8Xvf2onOxthyaBSr98+hVB7z4= +knative.dev/pkg v0.0.0-20210908025933-71508fc69a57/go.mod h1:jMSqkNMsrzuy+XR4Yr/BMy7SDVbUOl3KKB6+5MR+ZU8= pgregory.net/rapid v0.3.3/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= diff --git a/vendor/knative.dev/pkg/apis/duck/v1/podspec_defaults.go b/vendor/knative.dev/pkg/apis/duck/v1/podspec_defaults.go index 9fc3f3ce..1c6acb1e 100644 --- a/vendor/knative.dev/pkg/apis/duck/v1/podspec_defaults.go +++ b/vendor/knative.dev/pkg/apis/duck/v1/podspec_defaults.go @@ -30,7 +30,7 @@ func (wp *WithPod) SetDefaults(ctx context.Context) { } } -// psvKey is used for associating a PodSpecDefaulter with a context.Context +// psdKey is used for associating a PodSpecDefaulter with a context.Context type psdKey struct{} func WithPodSpecDefaulter(ctx context.Context, psd PodSpecDefaulter) context.Context { @@ -45,3 +45,29 @@ func GetPodSpecDefaulter(ctx context.Context) PodSpecDefaulter { } return untyped.(PodSpecDefaulter) } + +// PodDefaulter is a callback to validate a Pod. +type PodDefaulter func(context.Context, *Pod) + +// SetDefaults implements apis.Defaultable +func (p *Pod) SetDefaults(ctx context.Context) { + if pd := GetPodDefaulter(ctx); pd != nil { + pd(ctx, p) + } +} + +// pdKey is used for associating a PodDefaulter with a context.Context +type pdKey struct{} + +func WithPodDefaulter(ctx context.Context, pd PodDefaulter) context.Context { + return context.WithValue(ctx, pdKey{}, pd) +} + +// GetPodDefaulter extracts the PodDefaulter from the context. +func GetPodDefaulter(ctx context.Context) PodDefaulter { + untyped := ctx.Value(pdKey{}) + if untyped == nil { + return nil + } + return untyped.(PodDefaulter) +} diff --git a/vendor/knative.dev/pkg/apis/duck/v1/podspec_types.go b/vendor/knative.dev/pkg/apis/duck/v1/podspec_types.go index b822a484..7b1946e5 100644 --- a/vendor/knative.dev/pkg/apis/duck/v1/podspec_types.go +++ b/vendor/knative.dev/pkg/apis/duck/v1/podspec_types.go @@ -45,9 +45,6 @@ type WithPod struct { Spec WithPodSpec `json:"spec,omitempty"` } -var _ apis.Validatable = (*WithPod)(nil) -var _ apis.Defaultable = (*WithPod)(nil) - // WithPodSpec is the shell around the PodSpecable within WithPod. type WithPodSpec struct { Template PodSpecable `json:"template,omitempty"` @@ -55,6 +52,8 @@ type WithPodSpec struct { // Verify WithPod resources meet duck contracts. var ( + _ apis.Validatable = (*WithPod)(nil) + _ apis.Defaultable = (*WithPod)(nil) _ apis.Listable = (*WithPod)(nil) _ ducktypes.Populatable = (*WithPod)(nil) ) @@ -95,3 +94,52 @@ type WithPodList struct { Items []WithPod `json:"items"` } + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Pod is a wrapper around Pod-like resource, which supports our interfaces +// for webhooks +type Pod struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec corev1.PodSpec `json:"spec,omitempty"` +} + +// Verify Pod resources meet duck contracts. +var ( + _ apis.Validatable = (*Pod)(nil) + _ apis.Defaultable = (*Pod)(nil) + _ apis.Listable = (*Pod)(nil) + _ ducktypes.Populatable = (*Pod)(nil) +) + +// GetFullType implements duck.Implementable +func (p *Pod) GetFullType() ducktypes.Populatable { + return &Pod{} +} + +// Populate implements duck.Populatable +func (p *Pod) Populate() { + p.Spec = corev1.PodSpec{ + Containers: []corev1.Container{{ + Name: "container-name", + Image: "container-image:latest", + }}, + } +} + +// GetListType implements apis.Listable +func (p *Pod) GetListType() runtime.Object { + return &PodList{} +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// PodList is a list of WithPod resources +type PodList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + + Items []WithPod `json:"items"` +} diff --git a/vendor/knative.dev/pkg/apis/duck/v1/podspec_validation.go b/vendor/knative.dev/pkg/apis/duck/v1/podspec_validation.go index 3f8f28b6..1ec6ef48 100644 --- a/vendor/knative.dev/pkg/apis/duck/v1/podspec_validation.go +++ b/vendor/knative.dev/pkg/apis/duck/v1/podspec_validation.go @@ -48,3 +48,30 @@ func GetPodSpecValidator(ctx context.Context) PodSpecValidator { } return untyped.(PodSpecValidator) } + +// PodValidator is a callback to validate Pods. +type PodValidator func(context.Context, *Pod) *apis.FieldError + +// Validate implements apis.Validatable +func (p *Pod) Validate(ctx context.Context) *apis.FieldError { + if pv := GetPodValidator(ctx); pv != nil { + return pv(ctx, p) + } + return nil +} + +// pvKey is used for associating a PodValidator with a context.Context +type pvKey struct{} + +func WithPodValidator(ctx context.Context, pv PodValidator) context.Context { + return context.WithValue(ctx, pvKey{}, pv) +} + +// GetPodValidator extracts the PodValidator from the context. +func GetPodValidator(ctx context.Context) PodValidator { + untyped := ctx.Value(pvKey{}) + if untyped == nil { + return nil + } + return untyped.(PodValidator) +} diff --git a/vendor/knative.dev/pkg/apis/duck/v1/zz_generated.deepcopy.go b/vendor/knative.dev/pkg/apis/duck/v1/zz_generated.deepcopy.go index ae98f046..22088b21 100644 --- a/vendor/knative.dev/pkg/apis/duck/v1/zz_generated.deepcopy.go +++ b/vendor/knative.dev/pkg/apis/duck/v1/zz_generated.deepcopy.go @@ -367,6 +367,66 @@ func (in *KResourceList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Pod) DeepCopyInto(out *Pod) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Pod. +func (in *Pod) DeepCopy() *Pod { + if in == nil { + return nil + } + out := new(Pod) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Pod) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PodList) DeepCopyInto(out *PodList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]WithPod, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodList. +func (in *PodList) DeepCopy() *PodList { + if in == nil { + return nil + } + out := new(PodList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *PodList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PodSpecable) DeepCopyInto(out *PodSpecable) { *out = *in diff --git a/vendor/modules.txt b/vendor/modules.txt index 7b6388c2..c144c8b9 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -612,7 +612,7 @@ k8s.io/utils/trace # knative.dev/hack v0.0.0-20210806075220-815cd312d65c ## explicit knative.dev/hack -# knative.dev/pkg v0.0.0-20210907232433-26db1ba732f6 +# knative.dev/pkg v0.0.0-20210908025933-71508fc69a57 ## explicit knative.dev/pkg/apis knative.dev/pkg/apis/duck