Skip to content

Commit 3f49ea6

Browse files
FORK: use a forked version of knative/pkg
Signed-off-by: Mathew Wicks <[email protected]>
1 parent 37aeba0 commit 3f49ea6

File tree

11 files changed

+94
-34
lines changed

11 files changed

+94
-34
lines changed

go.mod

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ module knative.dev/serving
22

33
go 1.21
44

5+
// note, we have forked `knative/pkg` to apply some changes:
6+
// - https://github.com/deployKF/knative-pkg/tree/fork-1.13
7+
//
8+
// to get the pseudo-version of the fork, run:
9+
// - go get github.com/deployKF/[email protected]
10+
//
11+
// remember to run `./hack/update-deps.sh` when updating the version
12+
replace knative.dev/pkg => github.com/deployKF/knative-pkg v0.0.0-20241017230044-3db6060cea05
13+
514
require (
615
github.com/ahmetb/gen-crd-api-reference-docs v0.3.1-0.20210609063737-0067dc6dcea2
716
github.com/davecgh/go-spew v1.1.1
@@ -35,7 +44,7 @@ require (
3544
knative.dev/caching v0.0.0-20240116080314-0a234c8b78ac
3645
knative.dev/hack v0.0.0-20240123162936-f3f03ac0ab1a
3746
knative.dev/networking v0.0.0-20240116081125-ce0738abf051
38-
knative.dev/pkg v0.0.0-20240116073220-b488e7be5902
47+
knative.dev/pkg v0.0.0
3948
sigs.k8s.io/yaml v1.4.0
4049
)
4150

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
145145
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
146146
github.com/deepmap/oapi-codegen v1.8.2 h1:SegyeYGcdi0jLLrpbCMoJxnUUn8GBXHsvr4rbzjuhfU=
147147
github.com/deepmap/oapi-codegen v1.8.2/go.mod h1:YLgSKSDv/bZQB7N4ws6luhozi3cEdRktEqrX88CvjIw=
148+
github.com/deployKF/knative-pkg v0.0.0-20241017230044-3db6060cea05 h1:lKPkJxVmxhvhnfZRdCBL+MuX7Ca/vP3XNHG/A1kG5N4=
149+
github.com/deployKF/knative-pkg v0.0.0-20241017230044-3db6060cea05/go.mod h1:NYk8mMYoLkO7CQWnNkti4YGGnvLxN6MIDbUvtgeo0C0=
148150
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
149151
github.com/dgryski/go-gk v0.0.0-20200319235926-a69029f61654 h1:XOPLOMn/zT4jIgxfxSsoXPxkrzz0FaCHwp33x5POJ+Q=
150152
github.com/dgryski/go-gk v0.0.0-20200319235926-a69029f61654/go.mod h1:qm+vckxRlDt0aOla0RYJJVeqHZlWfOm2UIxHaqPB46E=
@@ -943,8 +945,6 @@ knative.dev/hack v0.0.0-20240123162936-f3f03ac0ab1a h1:+4Mdk0Lt3LGAVEI6vYyhfjBlV
943945
knative.dev/hack v0.0.0-20240123162936-f3f03ac0ab1a/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
944946
knative.dev/networking v0.0.0-20240116081125-ce0738abf051 h1:bTRVfwmfu4/7U1YBcgBl1VANAwmal6zkoAI9p7PQwDY=
945947
knative.dev/networking v0.0.0-20240116081125-ce0738abf051/go.mod h1:rdzGL1OVP6VItEiJUN/FTCrDnIzkA6ykhSvaK+0Ne6o=
946-
knative.dev/pkg v0.0.0-20240116073220-b488e7be5902 h1:H6+JJN23fhwYWCHY1339sY6uhIyoUwDy1a8dN233fdk=
947-
knative.dev/pkg v0.0.0-20240116073220-b488e7be5902/go.mod h1:NYk8mMYoLkO7CQWnNkti4YGGnvLxN6MIDbUvtgeo0C0=
948948
pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw=
949949
pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
950950
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=

vendor/knative.dev/pkg/webhook/configmaps/configmaps.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ type reconciler struct {
5858
vwhlister admissionlisters.ValidatingWebhookConfigurationLister
5959
secretlister corelisters.SecretLister
6060

61-
secretName string
61+
secretName string
62+
disableNamespaceOwnership bool
6263
}
6364

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

137138
webhook := configuredWebhook.DeepCopy()
138139

139-
// Set the owner to namespace.
140-
ns, err := ac.client.CoreV1().Namespaces().Get(ctx, system.Namespace(), metav1.GetOptions{})
141-
if err != nil {
142-
return fmt.Errorf("failed to fetch namespace: %w", err)
140+
if !ac.disableNamespaceOwnership {
141+
// Set the owner to namespace.
142+
ns, err := ac.client.CoreV1().Namespaces().Get(ctx, system.Namespace(), metav1.GetOptions{})
143+
if err != nil {
144+
return fmt.Errorf("failed to fetch namespace: %w", err)
145+
}
146+
nsRef := *metav1.NewControllerRef(ns, corev1.SchemeGroupVersion.WithKind("Namespace"))
147+
webhook.OwnerReferences = []metav1.OwnerReference{nsRef}
143148
}
144-
nsRef := *metav1.NewControllerRef(ns, corev1.SchemeGroupVersion.WithKind("Namespace"))
145-
webhook.OwnerReferences = []metav1.OwnerReference{nsRef}
146149

147150
for i, wh := range webhook.Webhooks {
148151
if wh.Name != webhook.Name {

vendor/knative.dev/pkg/webhook/configmaps/controller.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ func NewAdmissionController(
4747
secretInformer := secretinformer.Get(ctx)
4848
options := webhook.GetOptions(ctx)
4949

50+
// if this environment variable is set, it overrides the value in the Options
51+
disableNamespaceOwnership := webhook.DisableNamespaceOwnershipFromEnv()
52+
if disableNamespaceOwnership != nil {
53+
options.DisableNamespaceOwnership = *disableNamespaceOwnership
54+
}
55+
5056
key := types.NamespacedName{Name: name}
5157

5258
wh := &reconciler{
@@ -61,8 +67,9 @@ func NewAdmissionController(
6167
key: key,
6268
path: path,
6369

64-
constructors: make(map[string]reflect.Value),
65-
secretName: options.SecretName,
70+
constructors: make(map[string]reflect.Value),
71+
secretName: options.SecretName,
72+
disableNamespaceOwnership: options.DisableNamespaceOwnership,
6673

6774
client: client,
6875
vwhlister: vwhInformer.Lister(),

vendor/knative.dev/pkg/webhook/env.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const (
3232
secretNameEnvKey = "WEBHOOK_SECRET_NAME" //nolint:gosec // This is not a hardcoded credential
3333

3434
tlsMinVersionEnvKey = "WEBHOOK_TLS_MIN_VERSION"
35+
36+
disableNamespaceOwnershipEnvKey = "WEBHOOK_DISABLE_NAMESPACE_OWNERSHIP"
3537
)
3638

3739
// PortFromEnv returns the webhook port set by portEnvKey, or default port if env var is not set.
@@ -82,3 +84,15 @@ func TLSMinVersionFromEnv(defaultTLSMinVersion uint16) uint16 {
8284
panic(fmt.Sprintf("the environment variable %q has to be either '1.2' or '1.3'", tlsMinVersionEnvKey))
8385
}
8486
}
87+
88+
func DisableNamespaceOwnershipFromEnv() *bool {
89+
disableNamespaceOwnership := os.Getenv(disableNamespaceOwnershipEnvKey)
90+
if disableNamespaceOwnership == "" {
91+
return nil
92+
}
93+
disableNamespaceOwnershipBool, err := strconv.ParseBool(disableNamespaceOwnership)
94+
if err != nil {
95+
panic(fmt.Sprintf("failed to convert the environment variable %q : %v", disableNamespaceOwnershipEnvKey, err))
96+
}
97+
return &disableNamespaceOwnershipBool
98+
}

vendor/knative.dev/pkg/webhook/resourcesemantics/defaulting/controller.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ func newController(ctx context.Context, name string, optsFunc ...OptionFunc) *co
8585
f(opts)
8686
}
8787

88+
// if this environment variable is set, it overrides the value in the Options
89+
disableNamespaceOwnership := webhook.DisableNamespaceOwnershipFromEnv()
90+
if disableNamespaceOwnership != nil {
91+
wopts.DisableNamespaceOwnership = *disableNamespaceOwnership
92+
}
93+
8894
key := types.NamespacedName{Name: name}
8995

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

104-
withContext: opts.wc,
105-
disallowUnknownFields: opts.disallowUnknownFields,
106-
secretName: wopts.SecretName,
110+
withContext: opts.wc,
111+
disallowUnknownFields: opts.disallowUnknownFields,
112+
secretName: wopts.SecretName,
113+
disableNamespaceOwnership: wopts.DisableNamespaceOwnership,
107114

108115
client: client,
109116
mwhlister: mwhInformer.Lister(),

vendor/knative.dev/pkg/webhook/resourcesemantics/defaulting/defaulting.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ type reconciler struct {
6969
mwhlister admissionlisters.MutatingWebhookConfigurationLister
7070
secretlister corelisters.SecretLister
7171

72-
disallowUnknownFields bool
73-
secretName string
72+
disallowUnknownFields bool
73+
secretName string
74+
disableNamespaceOwnership bool
7475
}
7576

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

217218
current := configuredWebhook.DeepCopy()
218219

219-
ns, err := ac.client.CoreV1().Namespaces().Get(ctx, system.Namespace(), metav1.GetOptions{})
220-
if err != nil {
221-
return fmt.Errorf("failed to fetch namespace: %w", err)
220+
if !ac.disableNamespaceOwnership {
221+
ns, err := ac.client.CoreV1().Namespaces().Get(ctx, system.Namespace(), metav1.GetOptions{})
222+
if err != nil {
223+
return fmt.Errorf("failed to fetch namespace: %w", err)
224+
}
225+
nsRef := *metav1.NewControllerRef(ns, corev1.SchemeGroupVersion.WithKind("Namespace"))
226+
current.OwnerReferences = []metav1.OwnerReference{nsRef}
222227
}
223-
nsRef := *metav1.NewControllerRef(ns, corev1.SchemeGroupVersion.WithKind("Namespace"))
224-
current.OwnerReferences = []metav1.OwnerReference{nsRef}
225228

226229
for i, wh := range current.Webhooks {
227230
if wh.Name != current.Name {

vendor/knative.dev/pkg/webhook/resourcesemantics/validation/controller.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ func newController(ctx context.Context, name string, optsFunc ...OptionFunc) *co
7171
f(opts)
7272
}
7373

74+
// if this environment variable is set, it overrides the value in the Options
75+
disableNamespaceOwnership := webhook.DisableNamespaceOwnershipFromEnv()
76+
if disableNamespaceOwnership != nil {
77+
woptions.DisableNamespaceOwnership = *disableNamespaceOwnership
78+
}
79+
7480
wh := &reconciler{
7581
LeaderAwareFuncs: pkgreconciler.LeaderAwareFuncs{
7682
// Have this reconciler enqueue our singleton whenever it becomes leader.
@@ -87,9 +93,10 @@ func newController(ctx context.Context, name string, optsFunc ...OptionFunc) *co
8793
handlers: opts.types,
8894
callbacks: opts.callbacks,
8995

90-
withContext: opts.wc,
91-
disallowUnknownFields: opts.DisallowUnknownFields(),
92-
secretName: woptions.SecretName,
96+
withContext: opts.wc,
97+
disallowUnknownFields: opts.DisallowUnknownFields(),
98+
secretName: woptions.SecretName,
99+
disableNamespaceOwnership: woptions.DisableNamespaceOwnership,
93100

94101
client: client,
95102
vwhlister: vwhInformer.Lister(),

vendor/knative.dev/pkg/webhook/resourcesemantics/validation/reconcile_config.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ type reconciler struct {
6060
vwhlister admissionlisters.ValidatingWebhookConfigurationLister
6161
secretlister corelisters.SecretLister
6262

63-
disallowUnknownFields bool
64-
secretName string
63+
disallowUnknownFields bool
64+
secretName string
65+
disableNamespaceOwnership bool
6566
}
6667

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

192193
current := configuredWebhook.DeepCopy()
193194

194-
// Set the owner to namespace.
195-
ns, err := ac.client.CoreV1().Namespaces().Get(ctx, system.Namespace(), metav1.GetOptions{})
196-
if err != nil {
197-
return fmt.Errorf("failed to fetch namespace: %w", err)
195+
if !ac.disableNamespaceOwnership {
196+
// Set the owner to namespace.
197+
ns, err := ac.client.CoreV1().Namespaces().Get(ctx, system.Namespace(), metav1.GetOptions{})
198+
if err != nil {
199+
return fmt.Errorf("failed to fetch namespace: %w", err)
200+
}
201+
nsRef := *metav1.NewControllerRef(ns, corev1.SchemeGroupVersion.WithKind("Namespace"))
202+
current.OwnerReferences = []metav1.OwnerReference{nsRef}
198203
}
199-
nsRef := *metav1.NewControllerRef(ns, corev1.SchemeGroupVersion.WithKind("Namespace"))
200-
current.OwnerReferences = []metav1.OwnerReference{nsRef}
201204

202205
for i, wh := range current.Webhooks {
203206
if wh.Name != current.Name {

vendor/knative.dev/pkg/webhook/webhook.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ type Options struct {
7878
// before shutting down.
7979
GracePeriod time.Duration
8080

81+
// DisableNamespaceOwnership configures if the SYSTEM_NAMESPACE is added as an owner reference to the
82+
// webhook configuration resources. Overridden by the WEBHOOK_DISABLE_NAMESPACE_OWNERSHIP environment variable.
83+
// Disabling can be useful to avoid breaking systems that expect ownership to indicate a true controller
84+
// relationship: https://github.com/knative/serving/issues/15483
85+
DisableNamespaceOwnership bool
86+
8187
// ControllerOptions encapsulates options for creating a new controller,
8288
// including throttling and stats behavior.
8389
ControllerOptions *controller.ControllerOptions

0 commit comments

Comments
 (0)