-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add validating webhook for config-gateway Config Map (#705)
* add validation webhook for configmap * add EOF new line in yaml files * run ./hack/update-deps.sh * rename config-gateway yaml file * renamed yaml files * add object selector labels to config-gateway in contour folder
- Loading branch information
Showing
14 changed files
with
889 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
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 main | ||
|
||
import ( | ||
"context" | ||
|
||
gatewayapiconfig "knative.dev/net-gateway-api/pkg/reconciler/ingress/config" | ||
"knative.dev/pkg/configmap" | ||
"knative.dev/pkg/controller" | ||
"knative.dev/pkg/injection/sharedmain" | ||
"knative.dev/pkg/signals" | ||
"knative.dev/pkg/webhook" | ||
"knative.dev/pkg/webhook/certificates" | ||
"knative.dev/pkg/webhook/configmaps" | ||
) | ||
|
||
func NewConfigValidationController(ctx context.Context, _ configmap.Watcher) *controller.Impl { | ||
return configmaps.NewAdmissionController(ctx, | ||
|
||
// Name of the resource webhook. | ||
"config.webhook.gateway-api.networking.internal.knative.dev", | ||
|
||
// The path on which to serve the webhook. | ||
"/config-validation", | ||
|
||
// The configmaps to validate. | ||
configmap.Constructors{ | ||
gatewayapiconfig.GatewayConfigName: gatewayapiconfig.FromConfigMap, | ||
}, | ||
) | ||
} | ||
|
||
func main() { | ||
ctx := webhook.WithOptions(signals.NewContext(), webhook.Options{ | ||
ServiceName: "net-gateway-api-webhook", | ||
SecretName: "net-gateway-api-webhook-certs", | ||
Port: webhook.PortFromEnv(8443), | ||
}) | ||
|
||
ctx = sharedmain.WithHealthProbesDisabled(ctx) | ||
sharedmain.WebhookMainWithContext( | ||
ctx, "net-gateway-api-webhook", | ||
certificates.NewController, | ||
NewConfigValidationController, | ||
) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# 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 | ||
# | ||
# https://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. | ||
|
||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: net-gateway-api-webhook | ||
namespace: knative-serving | ||
labels: | ||
app.kubernetes.io/component: net-gateway-api | ||
app.kubernetes.io/name: knative-serving | ||
app.kubernetes.io/version: devel | ||
networking.knative.dev/ingress-provider: gateway-api | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: net-gateway-api-webhook | ||
role: net-gateway-api-webhook | ||
template: | ||
metadata: | ||
labels: | ||
app: net-gateway-api-webhook | ||
role: net-gateway-api-webhook | ||
app.kubernetes.io/component: net-gateway-api | ||
app.kubernetes.io/name: knative-serving | ||
app.kubernetes.io/version: devel | ||
spec: | ||
serviceAccountName: controller | ||
containers: | ||
- name: webhook | ||
# This is the Go import path for the binary that is containerized | ||
# and substituted here. | ||
image: ko://knative.dev/net-gateway-api/cmd/webhook | ||
|
||
resources: | ||
requests: | ||
cpu: 20m | ||
memory: 20Mi | ||
limits: | ||
cpu: 200m | ||
memory: 200Mi | ||
|
||
env: | ||
- name: SYSTEM_NAMESPACE | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: metadata.namespace | ||
- name: CONFIG_LOGGING_NAME | ||
value: config-logging | ||
- name: CONFIG_OBSERVABILITY_NAME | ||
value: config-observability | ||
|
||
# TODO(https://github.com/knative/pkg/pull/953): Remove stackdriver specific config | ||
- name: METRICS_DOMAIN | ||
value: knative.dev/net-gateway-api | ||
- name: WEBHOOK_NAME | ||
value: net-gateway-api-webhook | ||
# If you change WEBHOOK_PORT, you will also need to change the | ||
# containerPort "https-webhook" to the same value. | ||
- name: WEBHOOK_PORT | ||
value: "8443" | ||
|
||
securityContext: | ||
runAsNonRoot: true | ||
allowPrivilegeEscalation: false | ||
capabilities: | ||
drop: | ||
- ALL | ||
seccompProfile: | ||
type: RuntimeDefault | ||
|
||
readinessProbe: | ||
periodSeconds: 1 | ||
httpGet: | ||
scheme: HTTPS | ||
port: 8443 | ||
failureThreshold: 3 | ||
livenessProbe: | ||
periodSeconds: 1 | ||
httpGet: | ||
scheme: HTTPS | ||
port: 8443 | ||
failureThreshold: 6 | ||
initialDelaySeconds: 20 | ||
|
||
ports: | ||
- name: metrics | ||
containerPort: 9090 | ||
- name: profiling | ||
containerPort: 8008 | ||
- name: https-webhook | ||
containerPort: 8443 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# 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 | ||
# | ||
# https://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. | ||
|
||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: net-gateway-api-webhook-certs | ||
namespace: knative-serving | ||
labels: | ||
app.kubernetes.io/component: net-gateway-api | ||
app.kubernetes.io/name: knative-serving | ||
app.kubernetes.io/version: devel | ||
networking.knative.dev/ingress-provider: gateway-api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# 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 | ||
# | ||
# https://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. | ||
|
||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: net-gateway-api-webhook | ||
namespace: knative-serving | ||
labels: | ||
role: net-gateway-api-webhook | ||
app.kubernetes.io/component: net-gateway-api | ||
app.kubernetes.io/name: knative-serving | ||
app.kubernetes.io/version: devel | ||
networking.knative.dev/ingress-provider: gateway-api | ||
spec: | ||
ports: | ||
# Define metrics and profiling for them to be accessible within service meshes. | ||
- name: http-metrics | ||
port: 9090 | ||
targetPort: metrics | ||
- name: http-profiling | ||
port: 8008 | ||
targetPort: profiling | ||
- name: https-webhook | ||
port: 443 | ||
targetPort: https-webhook | ||
selector: | ||
app: net-gateway-api-webhook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# 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 | ||
# | ||
# https://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. | ||
|
||
apiVersion: admissionregistration.k8s.io/v1 | ||
kind: ValidatingWebhookConfiguration | ||
metadata: | ||
name: config.webhook.gateway-api.networking.internal.knative.dev | ||
labels: | ||
app.kubernetes.io/component: net-gateway-api | ||
app.kubernetes.io/name: knative-serving | ||
app.kubernetes.io/version: devel | ||
networking.knative.dev/ingress-provider: gateway-api | ||
webhooks: | ||
- admissionReviewVersions: | ||
- v1 | ||
- v1beta1 | ||
clientConfig: | ||
service: | ||
name: net-gateway-api-webhook | ||
namespace: knative-serving | ||
failurePolicy: Fail | ||
sideEffects: None | ||
name: config.webhook.gateway-api.networking.internal.knative.dev | ||
objectSelector: | ||
matchLabels: | ||
app.kubernetes.io/name: knative-serving | ||
app.kubernetes.io/component: net-gateway-api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...admissionregistration/v1/validatingwebhookconfiguration/validatingwebhookconfiguration.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
vendor/knative.dev/pkg/injection/clients/namespacedkube/informers/core/v1/secret/secret.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
Copyright 2020 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 secret | ||
|
||
import ( | ||
context "context" | ||
|
||
v1 "k8s.io/client-go/informers/core/v1" | ||
controller "knative.dev/pkg/controller" | ||
injection "knative.dev/pkg/injection" | ||
factory "knative.dev/pkg/injection/clients/namespacedkube/informers/factory" | ||
logging "knative.dev/pkg/logging" | ||
) | ||
|
||
func init() { | ||
injection.Default.RegisterInformer(withInformer) | ||
} | ||
|
||
// Key is used for associating the Informer inside the context.Context. | ||
type Key struct{} | ||
|
||
func withInformer(ctx context.Context) (context.Context, controller.Informer) { | ||
f := factory.Get(ctx) | ||
inf := f.Core().V1().Secrets() | ||
return context.WithValue(ctx, Key{}, inf), inf.Informer() | ||
} | ||
|
||
// Get extracts the typed informer from the context. | ||
func Get(ctx context.Context) v1.SecretInformer { | ||
untyped := ctx.Value(Key{}) | ||
if untyped == nil { | ||
logging.FromContext(ctx).Panic( | ||
"Unable to fetch k8s.io/client-go/informers/core/v1.SecretInformer from context.") | ||
} | ||
return untyped.(v1.SecretInformer) | ||
} |
Oops, something went wrong.