Skip to content

Commit ed477b9

Browse files
FORK: use a forked version of knative/pkg
Signed-off-by: Mathew Wicks <5735406+thesuperzapper@users.noreply.github.com>
1 parent 7652d10 commit ed477b9

File tree

9 files changed

+73
-23
lines changed

9 files changed

+73
-23
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/net-istio
22

33
go 1.18
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/knative-pkg@fork-1.13
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/google/go-cmp v0.6.0
716
go.uber.org/zap v1.26.0
@@ -14,7 +23,7 @@ require (
1423
k8s.io/client-go v0.28.5
1524
knative.dev/hack v0.0.0-20240123162936-f3f03ac0ab1a
1625
knative.dev/networking v0.0.0-20240116081125-ce0738abf051
17-
knative.dev/pkg v0.0.0-20240116073220-b488e7be5902
26+
knative.dev/pkg v0.0.0
1827
)
1928

2029
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
6868
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6969
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
7070
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
71+
github.com/deployKF/knative-pkg v0.0.0-20241017230044-3db6060cea05 h1:lKPkJxVmxhvhnfZRdCBL+MuX7Ca/vP3XNHG/A1kG5N4=
72+
github.com/deployKF/knative-pkg v0.0.0-20241017230044-3db6060cea05/go.mod h1:NYk8mMYoLkO7CQWnNkti4YGGnvLxN6MIDbUvtgeo0C0=
7173
github.com/emicklei/go-restful/v3 v3.9.0 h1:XwGDlfxEnQZzuopoqxwSEllNcCOM9DhhFyhFIIGKwxE=
7274
github.com/emicklei/go-restful/v3 v3.9.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
7375
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
@@ -691,8 +693,6 @@ knative.dev/hack v0.0.0-20240123162936-f3f03ac0ab1a h1:+4Mdk0Lt3LGAVEI6vYyhfjBlV
691693
knative.dev/hack v0.0.0-20240123162936-f3f03ac0ab1a/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
692694
knative.dev/networking v0.0.0-20240116081125-ce0738abf051 h1:bTRVfwmfu4/7U1YBcgBl1VANAwmal6zkoAI9p7PQwDY=
693695
knative.dev/networking v0.0.0-20240116081125-ce0738abf051/go.mod h1:rdzGL1OVP6VItEiJUN/FTCrDnIzkA6ykhSvaK+0Ne6o=
694-
knative.dev/pkg v0.0.0-20240116073220-b488e7be5902 h1:H6+JJN23fhwYWCHY1339sY6uhIyoUwDy1a8dN233fdk=
695-
knative.dev/pkg v0.0.0-20240116073220-b488e7be5902/go.mod h1:NYk8mMYoLkO7CQWnNkti4YGGnvLxN6MIDbUvtgeo0C0=
696696
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
697697
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
698698
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

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/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

vendor/modules.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ knative.dev/networking/test/test_images/runtime/handlers
970970
knative.dev/networking/test/test_images/timeout
971971
knative.dev/networking/test/test_images/wsserver
972972
knative.dev/networking/test/types
973-
# knative.dev/pkg v0.0.0-20240116073220-b488e7be5902
973+
# knative.dev/pkg v0.0.0 => github.com/deployKF/knative-pkg v0.0.0-20241017230044-3db6060cea05
974974
## explicit; go 1.18
975975
knative.dev/pkg/apis
976976
knative.dev/pkg/apis/duck
@@ -1066,3 +1066,4 @@ sigs.k8s.io/structured-merge-diff/v4/value
10661066
## explicit; go 1.12
10671067
sigs.k8s.io/yaml
10681068
sigs.k8s.io/yaml/goyaml.v2
1069+
# knative.dev/pkg => github.com/deployKF/knative-pkg v0.0.0-20241017230044-3db6060cea05

0 commit comments

Comments
 (0)