Skip to content

Commit

Permalink
test == v4
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed Aug 31, 2024
1 parent f63a05d commit e299edc
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/testdata/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function scaffold_test_project {
$kb create api --group example.com --version v1alpha1 --kind Busybox --image=busybox:1.36.1 --plugins="deploy-image/v1-alpha" --make=false
header_text 'Creating Memcached webhook ...'
$kb create webhook --group example.com --version v1alpha1 --kind Memcached --defaulting --programmatic-validation
$kb create webhook --group example.com --version v1alpha1 --kind Busybox --conversion
fi

if [[ $project == project-v4-with-grafana ]]; then
Expand Down
3 changes: 3 additions & 0 deletions testdata/project-v4-with-deploy-image/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ resources:
kind: Busybox
path: sigs.k8s.io/kubebuilder/testdata/project-v4-with-deploy-image/api/v1alpha1
version: v1alpha1
webhooks:
conversion: true
webhookVersion: v1
version: "3"
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright 2024 The Kubernetes 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 v1alpha1

import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

// nolint:unused
// log is for logging in this package.
var busyboxlog = logf.Log.WithName("busybox-resource")

// SetupWebhookWithManager will setup the manager to manage the webhooks
func (r *Busybox) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
Complete()
}

// TODO(user): EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2024 The Kubernetes 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 v1alpha1

import (
. "github.com/onsi/ginkgo/v2"
)

var _ = Describe("Busybox Webhook", func() {

Context("When creating Busybox under Conversion Webhook", func() {
It("Should get the converted version of Busybox", func() {

// TODO(user): Add your logic here

})
})

})
7 changes: 7 additions & 0 deletions testdata/project-v4-with-deploy-image/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ func main() {
os.Exit(1)
}
}
// nolint:goconst
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
if err = (&examplecomv1alpha1.Busybox{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Busybox")
os.Exit(1)
}
}
// +kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ patches:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
- path: patches/webhook_in_memcacheds.yaml
- path: patches/webhook_in_busyboxes.yaml
# +kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: CERTIFICATE_NAMESPACE/CERTIFICATE_NAME
name: busyboxes.example.com.testproject.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# The following patch enables a conversion webhook for the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: busyboxes.example.com.testproject.org
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
conversionReviewVersions:
- v1
10 changes: 10 additions & 0 deletions testdata/project-v4-with-deploy-image/dist/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ metadata:
controller-gen.kubebuilder.io/version: v0.16.1
name: busyboxes.example.com.testproject.org
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
name: project-v4-with-deploy-image-webhook-service
namespace: project-v4-with-deploy-image-system
path: /convert
conversionReviewVersions:
- v1
group: example.com.testproject.org
names:
kind: Busybox
Expand Down

0 comments on commit e299edc

Please sign in to comment.