Skip to content

Commit

Permalink
upgrade to latest dependencies (#15329)
Browse files Browse the repository at this point in the history
bumping knative.dev/networking 85e269d...3b8764c:
  > 3b8764c upgrade to latest dependencies (# 989)
bumping knative.dev/pkg 15e6cdf...339c22b:
  > 339c22b Add AuthenticatableType duck type (# 3056)

Signed-off-by: Knative Automation <automation@knative.team>
  • Loading branch information
knative-automation authored Jun 17, 2024
1 parent 0b61640 commit f464e2d
Show file tree
Hide file tree
Showing 7 changed files with 360 additions and 8 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ require (
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
knative.dev/caching v0.0.0-20240610144728-23ec42b2186b
knative.dev/hack v0.0.0-20240607132042-09143140a254
knative.dev/networking v0.0.0-20240607132834-85e269dff522
knative.dev/pkg v0.0.0-20240610120318-15e6cdf2f386
knative.dev/networking v0.0.0-20240611072033-3b8764c0bb4c
knative.dev/pkg v0.0.0-20240614135239-339c22b8218c
sigs.k8s.io/yaml v1.4.0
)

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -949,10 +949,10 @@ knative.dev/caching v0.0.0-20240610144728-23ec42b2186b h1:DNlfCXdLU4tTfICxG1A4Kw
knative.dev/caching v0.0.0-20240610144728-23ec42b2186b/go.mod h1:cMG3/sqFSXue9pM9zL47SMKW/xl1390e6FwMP+iRfZE=
knative.dev/hack v0.0.0-20240607132042-09143140a254 h1:1YFnu3U6dWZg0oxm6GU8kEdA9A+BvSWKJO7sg3N0kq8=
knative.dev/hack v0.0.0-20240607132042-09143140a254/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
knative.dev/networking v0.0.0-20240607132834-85e269dff522 h1:zDtZStHJI3La7jSHUAjN4Jgv0/Yynl51kuchlVLHqzA=
knative.dev/networking v0.0.0-20240607132834-85e269dff522/go.mod h1:WS5A291Vy2unZ1L54ZSKBkz/gVzVmIy15cCcdA6PRN4=
knative.dev/pkg v0.0.0-20240610120318-15e6cdf2f386 h1:nxFTT6DrXr70Zi2BK8nc57ts0/smyavd/uBRBbtqg94=
knative.dev/pkg v0.0.0-20240610120318-15e6cdf2f386/go.mod h1:l7R8/SteYph0mZDsVgq3fVs4mWp1DaYx9BJJX68U6ik=
knative.dev/networking v0.0.0-20240611072033-3b8764c0bb4c h1:Q+DdJYzvhwAVWMQtP6mbEr5dNxpr+K9HAF9RqJmZefY=
knative.dev/networking v0.0.0-20240611072033-3b8764c0bb4c/go.mod h1:WhZLv94eOMDGHbdZiMrw6cnRfN3WEcFgpjUcV0A48pI=
knative.dev/pkg v0.0.0-20240614135239-339c22b8218c h1:OaKrY7L6rzWTvs51JlieJajL40F6CpBbvO1aZspg2EA=
knative.dev/pkg v0.0.0-20240614135239-339c22b8218c/go.mod h1:l7R8/SteYph0mZDsVgq3fVs4mWp1DaYx9BJJX68U6ik=
pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw=
pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
Expand Down
93 changes: 93 additions & 0 deletions vendor/knative.dev/pkg/apis/duck/v1/auth_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ limitations under the License.

package v1

import (
"context"
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/pkg/apis"
"knative.dev/pkg/apis/duck/ducktypes"
"knative.dev/pkg/kmeta"
"knative.dev/pkg/ptr"
)

// +genduck

// AuthStatus is meant to provide the generated service account name
// in the resource status.
type AuthStatus struct {
Expand All @@ -28,3 +43,81 @@ type AuthStatus struct {
// when the component uses multiple identities (e.g. in case of a Parallel).
ServiceAccountNames []string `json:"serviceAccountNames,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// AuthenticatableType is a skeleton type wrapping AuthStatus in the manner we expect
// resource writers defining compatible resources to embed it. We will
// typically use this type to deserialize AuthenticatableType ObjectReferences and
// access the AuthenticatableType data. This is not a real resource.
type AuthenticatableType struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Status AuthenticatableStatus `json:"status"`
}

type AuthenticatableStatus struct {
// Auth contains the service account name for the subscription
// +optional
Auth *AuthStatus `json:"auth,omitempty"`
}

var (
// AuthStatus is a Convertible type.
_ apis.Convertible = (*AuthStatus)(nil)

// Verify AuthenticatableType resources meet duck contracts.
_ apis.Listable = (*AuthenticatableType)(nil)
_ ducktypes.Populatable = (*AuthenticatableType)(nil)
_ kmeta.OwnerRefable = (*AuthenticatableType)(nil)
)

// GetFullType implements duck.Implementable
func (*AuthStatus) GetFullType() ducktypes.Populatable {
return &AuthenticatableType{}
}

// ConvertTo implements apis.Convertible
func (a *AuthStatus) ConvertTo(_ context.Context, to apis.Convertible) error {
return fmt.Errorf("v1 is the highest known version, got: %T", to)
}

// ConvertFrom implements apis.Convertible
func (a *AuthStatus) ConvertFrom(_ context.Context, from apis.Convertible) error {
return fmt.Errorf("v1 is the highest known version, got: %T", from)
}

// Populate implements duck.Populatable
func (t *AuthenticatableType) Populate() {
t.Status = AuthenticatableStatus{
Auth: &AuthStatus{
// Populate ALL fields
ServiceAccountName: ptr.String("foo"),
ServiceAccountNames: []string{
"bar",
"baz",
},
},
}
}

// GetGroupVersionKind implements kmeta.OwnerRefable
func (t *AuthenticatableType) GetGroupVersionKind() schema.GroupVersionKind {
return t.GroupVersionKind()
}

// GetListType implements apis.Listable
func (*AuthenticatableType) GetListType() runtime.Object {
return &AuthenticatableTypeList{}
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// AuthenticatableTypeList is a list of AuthenticatableType resources
type AuthenticatableTypeList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []AuthenticatableType `json:"items"`
}
81 changes: 81 additions & 0 deletions vendor/knative.dev/pkg/apis/duck/v1/zz_generated.deepcopy.go

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

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

117 changes: 117 additions & 0 deletions vendor/knative.dev/pkg/resolver/authenticatable_resolver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
Copyright 2024 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package resolver

import (
"context"
"fmt"

"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/tools/cache"

corev1 "k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"knative.dev/pkg/client/injection/ducks/duck/v1/authstatus"
"knative.dev/pkg/controller"

pkgapisduck "knative.dev/pkg/apis/duck"
duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/pkg/tracker"
)

// AuthenticatableResolver resolves ObjectReferences into a AuthenticatableType.
type AuthenticatableResolver struct {
tracker tracker.Interface
listerFactory func(schema.GroupVersionResource) (cache.GenericLister, error)
}

// NewAuthenticatableResolverFromTracker constructs a new AuthenticatableResolver with context and a tracker.
func NewAuthenticatableResolverFromTracker(ctx context.Context, t tracker.Interface) *AuthenticatableResolver {
ret := &AuthenticatableResolver{
tracker: t,
}

informerFactory := &pkgapisduck.CachedInformerFactory{
Delegate: &pkgapisduck.EnqueueInformerFactory{
Delegate: authstatus.Get(ctx),
EventHandler: controller.HandleAll(ret.tracker.OnChanged),
},
}

ret.listerFactory = func(gvr schema.GroupVersionResource) (cache.GenericLister, error) {
_, l, err := informerFactory.Get(ctx, gvr)
return l, err
}

return ret
}

// AuthStatusFromObjectReference returns the AuthStatus from an object
func (r *AuthenticatableResolver) AuthStatusFromObjectReference(ref *corev1.ObjectReference, parent interface{}) (*duckv1.AuthStatus, error) {
if ref == nil {
return nil, apierrs.NewBadRequest("ref is nil")
}

authenticatable, err := r.authenticatableFromObjectReference(ref, parent)
if err != nil {
return nil, fmt.Errorf("failed to get authenticatable %s/%s: %w", ref.Namespace, ref.Name, err)
}

if authenticatable.Status.Auth == nil {
return nil, fmt.Errorf(".status.auth is missing in object %s/%s", ref.Namespace, ref.Name)
}

return authenticatable.Status.Auth, nil
}

// authenticatableFromObjectReference resolves an object reference into an AuthenticatableType
func (r *AuthenticatableResolver) authenticatableFromObjectReference(ref *corev1.ObjectReference, parent interface{}) (*duckv1.AuthenticatableType, error) {
if ref == nil {
return nil, apierrs.NewBadRequest("ref is nil")
}

gvr, _ := meta.UnsafeGuessKindToResource(ref.GroupVersionKind())
if err := r.tracker.TrackReference(tracker.Reference{
APIVersion: ref.APIVersion,
Kind: ref.Kind,
Namespace: ref.Namespace,
Name: ref.Name,
}, parent); err != nil {
return nil, fmt.Errorf("failed to track reference %s %s/%s: %w", gvr.String(), ref.Namespace, ref.Name, err)
}

lister, err := r.listerFactory(gvr)
if err != nil {
return nil, fmt.Errorf("failed to get lister for %s: %w", gvr.String(), err)
}

obj, err := lister.ByNamespace(ref.Namespace).Get(ref.Name)
if err != nil {
return nil, fmt.Errorf("failed to get object %s/%s: %w", ref.Namespace, ref.Name, err)
}

authenticatable, ok := obj.(*duckv1.AuthenticatableType)
if !ok {
return nil, apierrs.NewBadRequest(fmt.Sprintf("%s(%T) is not an AuthenticatableType", ref, ref))
}

// Do not modify informer copy.
authenticatable = authenticatable.DeepCopy()

return authenticatable, nil
}
Loading

0 comments on commit f464e2d

Please sign in to comment.