Skip to content

Commit

Permalink
FORK: use a forked version of knative/pkg
Browse files Browse the repository at this point in the history
Signed-off-by: Mathew Wicks <5735406+thesuperzapper@users.noreply.github.com>
  • Loading branch information
thesuperzapper committed Oct 17, 2024
1 parent 37aeba0 commit 3f49ea6
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 34 deletions.
11 changes: 10 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ module knative.dev/serving

go 1.21

// note, we have forked `knative/pkg` to apply some changes:
// - https://github.com/deployKF/knative-pkg/tree/fork-1.13
//
// to get the pseudo-version of the fork, run:
// - go get github.com/deployKF/knative-pkg@fork-1.13
//
// remember to run `./hack/update-deps.sh` when updating the version
replace knative.dev/pkg => github.com/deployKF/knative-pkg v0.0.0-20241017230044-3db6060cea05

require (
github.com/ahmetb/gen-crd-api-reference-docs v0.3.1-0.20210609063737-0067dc6dcea2
github.com/davecgh/go-spew v1.1.1
Expand Down Expand Up @@ -35,7 +44,7 @@ require (
knative.dev/caching v0.0.0-20240116080314-0a234c8b78ac
knative.dev/hack v0.0.0-20240123162936-f3f03ac0ab1a
knative.dev/networking v0.0.0-20240116081125-ce0738abf051
knative.dev/pkg v0.0.0-20240116073220-b488e7be5902
knative.dev/pkg v0.0.0
sigs.k8s.io/yaml v1.4.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/deepmap/oapi-codegen v1.8.2 h1:SegyeYGcdi0jLLrpbCMoJxnUUn8GBXHsvr4rbzjuhfU=
github.com/deepmap/oapi-codegen v1.8.2/go.mod h1:YLgSKSDv/bZQB7N4ws6luhozi3cEdRktEqrX88CvjIw=
github.com/deployKF/knative-pkg v0.0.0-20241017230044-3db6060cea05 h1:lKPkJxVmxhvhnfZRdCBL+MuX7Ca/vP3XNHG/A1kG5N4=
github.com/deployKF/knative-pkg v0.0.0-20241017230044-3db6060cea05/go.mod h1:NYk8mMYoLkO7CQWnNkti4YGGnvLxN6MIDbUvtgeo0C0=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-gk v0.0.0-20200319235926-a69029f61654 h1:XOPLOMn/zT4jIgxfxSsoXPxkrzz0FaCHwp33x5POJ+Q=
github.com/dgryski/go-gk v0.0.0-20200319235926-a69029f61654/go.mod h1:qm+vckxRlDt0aOla0RYJJVeqHZlWfOm2UIxHaqPB46E=
Expand Down Expand Up @@ -943,8 +945,6 @@ knative.dev/hack v0.0.0-20240123162936-f3f03ac0ab1a h1:+4Mdk0Lt3LGAVEI6vYyhfjBlV
knative.dev/hack v0.0.0-20240123162936-f3f03ac0ab1a/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
knative.dev/networking v0.0.0-20240116081125-ce0738abf051 h1:bTRVfwmfu4/7U1YBcgBl1VANAwmal6zkoAI9p7PQwDY=
knative.dev/networking v0.0.0-20240116081125-ce0738abf051/go.mod h1:rdzGL1OVP6VItEiJUN/FTCrDnIzkA6ykhSvaK+0Ne6o=
knative.dev/pkg v0.0.0-20240116073220-b488e7be5902 h1:H6+JJN23fhwYWCHY1339sY6uhIyoUwDy1a8dN233fdk=
knative.dev/pkg v0.0.0-20240116073220-b488e7be5902/go.mod h1:NYk8mMYoLkO7CQWnNkti4YGGnvLxN6MIDbUvtgeo0C0=
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
17 changes: 10 additions & 7 deletions vendor/knative.dev/pkg/webhook/configmaps/configmaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ type reconciler struct {
vwhlister admissionlisters.ValidatingWebhookConfigurationLister
secretlister corelisters.SecretLister

secretName string
secretName string
disableNamespaceOwnership bool
}

var _ controller.Reconciler = (*reconciler)(nil)
Expand Down Expand Up @@ -136,13 +137,15 @@ func (ac *reconciler) reconcileValidatingWebhook(ctx context.Context, caCert []b

webhook := configuredWebhook.DeepCopy()

// Set the owner to namespace.
ns, err := ac.client.CoreV1().Namespaces().Get(ctx, system.Namespace(), metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to fetch namespace: %w", err)
if !ac.disableNamespaceOwnership {
// Set the owner to namespace.
ns, err := ac.client.CoreV1().Namespaces().Get(ctx, system.Namespace(), metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to fetch namespace: %w", err)
}
nsRef := *metav1.NewControllerRef(ns, corev1.SchemeGroupVersion.WithKind("Namespace"))
webhook.OwnerReferences = []metav1.OwnerReference{nsRef}
}
nsRef := *metav1.NewControllerRef(ns, corev1.SchemeGroupVersion.WithKind("Namespace"))
webhook.OwnerReferences = []metav1.OwnerReference{nsRef}

for i, wh := range webhook.Webhooks {
if wh.Name != webhook.Name {
Expand Down
11 changes: 9 additions & 2 deletions vendor/knative.dev/pkg/webhook/configmaps/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func NewAdmissionController(
secretInformer := secretinformer.Get(ctx)
options := webhook.GetOptions(ctx)

// if this environment variable is set, it overrides the value in the Options
disableNamespaceOwnership := webhook.DisableNamespaceOwnershipFromEnv()
if disableNamespaceOwnership != nil {
options.DisableNamespaceOwnership = *disableNamespaceOwnership
}

key := types.NamespacedName{Name: name}

wh := &reconciler{
Expand All @@ -61,8 +67,9 @@ func NewAdmissionController(
key: key,
path: path,

constructors: make(map[string]reflect.Value),
secretName: options.SecretName,
constructors: make(map[string]reflect.Value),
secretName: options.SecretName,
disableNamespaceOwnership: options.DisableNamespaceOwnership,

client: client,
vwhlister: vwhInformer.Lister(),
Expand Down
14 changes: 14 additions & 0 deletions vendor/knative.dev/pkg/webhook/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const (
secretNameEnvKey = "WEBHOOK_SECRET_NAME" //nolint:gosec // This is not a hardcoded credential

tlsMinVersionEnvKey = "WEBHOOK_TLS_MIN_VERSION"

disableNamespaceOwnershipEnvKey = "WEBHOOK_DISABLE_NAMESPACE_OWNERSHIP"
)

// PortFromEnv returns the webhook port set by portEnvKey, or default port if env var is not set.
Expand Down Expand Up @@ -82,3 +84,15 @@ func TLSMinVersionFromEnv(defaultTLSMinVersion uint16) uint16 {
panic(fmt.Sprintf("the environment variable %q has to be either '1.2' or '1.3'", tlsMinVersionEnvKey))
}
}

func DisableNamespaceOwnershipFromEnv() *bool {
disableNamespaceOwnership := os.Getenv(disableNamespaceOwnershipEnvKey)
if disableNamespaceOwnership == "" {
return nil
}
disableNamespaceOwnershipBool, err := strconv.ParseBool(disableNamespaceOwnership)
if err != nil {
panic(fmt.Sprintf("failed to convert the environment variable %q : %v", disableNamespaceOwnershipEnvKey, err))
}
return &disableNamespaceOwnershipBool
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ func newController(ctx context.Context, name string, optsFunc ...OptionFunc) *co
f(opts)
}

// if this environment variable is set, it overrides the value in the Options
disableNamespaceOwnership := webhook.DisableNamespaceOwnershipFromEnv()
if disableNamespaceOwnership != nil {
wopts.DisableNamespaceOwnership = *disableNamespaceOwnership
}

key := types.NamespacedName{Name: name}

wh := &reconciler{
Expand All @@ -101,9 +107,10 @@ func newController(ctx context.Context, name string, optsFunc ...OptionFunc) *co
handlers: opts.types,
callbacks: opts.callbacks,

withContext: opts.wc,
disallowUnknownFields: opts.disallowUnknownFields,
secretName: wopts.SecretName,
withContext: opts.wc,
disallowUnknownFields: opts.disallowUnknownFields,
secretName: wopts.SecretName,
disableNamespaceOwnership: wopts.DisableNamespaceOwnership,

client: client,
mwhlister: mwhInformer.Lister(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ type reconciler struct {
mwhlister admissionlisters.MutatingWebhookConfigurationLister
secretlister corelisters.SecretLister

disallowUnknownFields bool
secretName string
disallowUnknownFields bool
secretName string
disableNamespaceOwnership bool
}

// CallbackFunc is the function to be invoked.
Expand Down Expand Up @@ -216,12 +217,14 @@ func (ac *reconciler) reconcileMutatingWebhook(ctx context.Context, caCert []byt

current := configuredWebhook.DeepCopy()

ns, err := ac.client.CoreV1().Namespaces().Get(ctx, system.Namespace(), metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to fetch namespace: %w", err)
if !ac.disableNamespaceOwnership {
ns, err := ac.client.CoreV1().Namespaces().Get(ctx, system.Namespace(), metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to fetch namespace: %w", err)
}
nsRef := *metav1.NewControllerRef(ns, corev1.SchemeGroupVersion.WithKind("Namespace"))
current.OwnerReferences = []metav1.OwnerReference{nsRef}
}
nsRef := *metav1.NewControllerRef(ns, corev1.SchemeGroupVersion.WithKind("Namespace"))
current.OwnerReferences = []metav1.OwnerReference{nsRef}

for i, wh := range current.Webhooks {
if wh.Name != current.Name {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ func newController(ctx context.Context, name string, optsFunc ...OptionFunc) *co
f(opts)
}

// if this environment variable is set, it overrides the value in the Options
disableNamespaceOwnership := webhook.DisableNamespaceOwnershipFromEnv()
if disableNamespaceOwnership != nil {
woptions.DisableNamespaceOwnership = *disableNamespaceOwnership
}

wh := &reconciler{
LeaderAwareFuncs: pkgreconciler.LeaderAwareFuncs{
// Have this reconciler enqueue our singleton whenever it becomes leader.
Expand All @@ -87,9 +93,10 @@ func newController(ctx context.Context, name string, optsFunc ...OptionFunc) *co
handlers: opts.types,
callbacks: opts.callbacks,

withContext: opts.wc,
disallowUnknownFields: opts.DisallowUnknownFields(),
secretName: woptions.SecretName,
withContext: opts.wc,
disallowUnknownFields: opts.DisallowUnknownFields(),
secretName: woptions.SecretName,
disableNamespaceOwnership: woptions.DisableNamespaceOwnership,

client: client,
vwhlister: vwhInformer.Lister(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ type reconciler struct {
vwhlister admissionlisters.ValidatingWebhookConfigurationLister
secretlister corelisters.SecretLister

disallowUnknownFields bool
secretName string
disallowUnknownFields bool
secretName string
disableNamespaceOwnership bool
}

var _ controller.Reconciler = (*reconciler)(nil)
Expand Down Expand Up @@ -191,13 +192,15 @@ func (ac *reconciler) reconcileValidatingWebhook(ctx context.Context, caCert []b

current := configuredWebhook.DeepCopy()

// Set the owner to namespace.
ns, err := ac.client.CoreV1().Namespaces().Get(ctx, system.Namespace(), metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to fetch namespace: %w", err)
if !ac.disableNamespaceOwnership {
// Set the owner to namespace.
ns, err := ac.client.CoreV1().Namespaces().Get(ctx, system.Namespace(), metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to fetch namespace: %w", err)
}
nsRef := *metav1.NewControllerRef(ns, corev1.SchemeGroupVersion.WithKind("Namespace"))
current.OwnerReferences = []metav1.OwnerReference{nsRef}
}
nsRef := *metav1.NewControllerRef(ns, corev1.SchemeGroupVersion.WithKind("Namespace"))
current.OwnerReferences = []metav1.OwnerReference{nsRef}

for i, wh := range current.Webhooks {
if wh.Name != current.Name {
Expand Down
6 changes: 6 additions & 0 deletions vendor/knative.dev/pkg/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ type Options struct {
// before shutting down.
GracePeriod time.Duration

// DisableNamespaceOwnership configures if the SYSTEM_NAMESPACE is added as an owner reference to the
// webhook configuration resources. Overridden by the WEBHOOK_DISABLE_NAMESPACE_OWNERSHIP environment variable.
// Disabling can be useful to avoid breaking systems that expect ownership to indicate a true controller
// relationship: https://github.com/knative/serving/issues/15483
DisableNamespaceOwnership bool

// ControllerOptions encapsulates options for creating a new controller,
// including throttling and stats behavior.
ControllerOptions *controller.ControllerOptions
Expand Down
3 changes: 2 additions & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,7 @@ knative.dev/networking/pkg/http/stats
knative.dev/networking/pkg/ingress
knative.dev/networking/pkg/k8s
knative.dev/networking/pkg/prober
# knative.dev/pkg v0.0.0-20240116073220-b488e7be5902
# knative.dev/pkg v0.0.0 => github.com/deployKF/knative-pkg v0.0.0-20241017230044-3db6060cea05
## explicit; go 1.18
knative.dev/pkg/apiextensions/storageversion
knative.dev/pkg/apiextensions/storageversion/cmd/migrate
Expand Down Expand Up @@ -1504,4 +1504,5 @@ sigs.k8s.io/structured-merge-diff/v4/value
## explicit; go 1.12
sigs.k8s.io/yaml
sigs.k8s.io/yaml/goyaml.v2
# knative.dev/pkg => github.com/deployKF/knative-pkg v0.0.0-20241017230044-3db6060cea05
# github.com/gorilla/websocket => github.com/gorilla/websocket v1.5.0

0 comments on commit 3f49ea6

Please sign in to comment.