Skip to content

Commit d92f184

Browse files
committed
wip: add conversion webhooks for LC and LM
1 parent c8470e7 commit d92f184

File tree

11 files changed

+305
-0
lines changed

11 files changed

+305
-0
lines changed

PROJECT

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ resources:
137137
kind: LinodeCluster
138138
path: github.com/linode/cluster-api-provider-linode/api/v1beta1
139139
version: v1beta1
140+
webhooks:
141+
conversion: true
142+
spoke:
143+
- v1alpha2
144+
webhookVersion: v1
140145
- api:
141146
crdVersion: v1
142147
namespaced: true
@@ -145,4 +150,9 @@ resources:
145150
kind: LinodeMachine
146151
path: github.com/linode/cluster-api-provider-linode/api/v1beta1
147152
version: v1beta1
153+
webhooks:
154+
conversion: true
155+
spoke:
156+
- v1alpha2
157+
webhookVersion: v1
148158
version: "3"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Copyright 2023 Akamai Technologies, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
20+
21+
// Hub marks this type as a conversion hub.
22+
func (*LinodeCluster) Hub() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Copyright 2023 Akamai Technologies, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
20+
21+
// Hub marks this type as a conversion hub.
22+
func (*LinodeMachine) Hub() {}

cmd/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ import (
5050
"github.com/linode/cluster-api-provider-linode/version"
5151

5252
infrastructurev1beta1 "github.com/linode/cluster-api-provider-linode/api/v1beta1"
53+
webhookv1beta1 "github.com/linode/cluster-api-provider-linode/internal/webhook/v1beta1"
54+
5355
// +kubebuilder:scaffold:imports
5456

5557
_ "go.uber.org/automaxprocs"
@@ -257,6 +259,20 @@ func setupManager(flags flagVars, linodeConfig, dnsConfig scope.ClientConfig) ma
257259
setupWebhooks(mgr)
258260
}
259261

262+
// nolint:goconst
263+
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
264+
if err := webhookv1beta1.SetupLinodeClusterWebhookWithManager(mgr); err != nil {
265+
setupLog.Error(err, "unable to create webhook", "webhook", "LinodeCluster")
266+
os.Exit(1)
267+
}
268+
}
269+
// nolint:goconst
270+
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
271+
if err := webhookv1beta1.SetupLinodeMachineWebhookWithManager(mgr); err != nil {
272+
setupLog.Error(err, "unable to create webhook", "webhook", "LinodeMachine")
273+
os.Exit(1)
274+
}
275+
}
260276
// +kubebuilder:scaffold:builder
261277

262278
setupHealthChecks(mgr)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# The following manifests contain a self-signed issuer CR and a metrics certificate CR.
2+
# More document can be found at https://docs.cert-manager.io
3+
apiVersion: cert-manager.io/v1
4+
kind: Certificate
5+
metadata:
6+
labels:
7+
app.kubernetes.io/name: cluster-api-provider-linode
8+
app.kubernetes.io/managed-by: kustomize
9+
name: metrics-certs # this name should match the one appeared in kustomizeconfig.yaml
10+
namespace: system
11+
spec:
12+
dnsNames:
13+
# SERVICE_NAME and SERVICE_NAMESPACE will be substituted by kustomize
14+
# replacements in the config/default/kustomization.yaml file.
15+
- SERVICE_NAME.SERVICE_NAMESPACE.svc
16+
- SERVICE_NAME.SERVICE_NAMESPACE.svc.cluster.local
17+
issuerRef:
18+
kind: Issuer
19+
name: selfsigned-issuer
20+
secretName: metrics-server-cert
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# The following manifests contain a self-signed issuer CR and a certificate CR.
2+
# More document can be found at https://docs.cert-manager.io
3+
apiVersion: cert-manager.io/v1
4+
kind: Certificate
5+
metadata:
6+
labels:
7+
app.kubernetes.io/name: cluster-api-provider-linode
8+
app.kubernetes.io/managed-by: kustomize
9+
name: serving-cert # this name should match the one appeared in kustomizeconfig.yaml
10+
namespace: system
11+
spec:
12+
# SERVICE_NAME and SERVICE_NAMESPACE will be substituted by kustomize
13+
# replacements in the config/default/kustomization.yaml file.
14+
dnsNames:
15+
- SERVICE_NAME.SERVICE_NAMESPACE.svc
16+
- SERVICE_NAME.SERVICE_NAMESPACE.svc.cluster.local
17+
issuerRef:
18+
kind: Issuer
19+
name: selfsigned-issuer
20+
secretName: webhook-server-cert

config/certmanager/issuer.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# The following manifest contains a self-signed issuer CR.
2+
# More information can be found at https://docs.cert-manager.io
3+
# WARNING: Targets CertManager v1.0. Check https://cert-manager.io/docs/installation/upgrading/ for breaking changes.
4+
apiVersion: cert-manager.io/v1
5+
kind: Issuer
6+
metadata:
7+
labels:
8+
app.kubernetes.io/name: cluster-api-provider-linode
9+
app.kubernetes.io/managed-by: kustomize
10+
name: selfsigned-issuer
11+
namespace: system
12+
spec:
13+
selfSigned: {}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2023 Akamai Technologies, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
ctrl "sigs.k8s.io/controller-runtime"
21+
logf "sigs.k8s.io/controller-runtime/pkg/log"
22+
23+
infrastructurev1beta1 "github.com/linode/cluster-api-provider-linode/api/v1beta1"
24+
)
25+
26+
// nolint:unused
27+
// log is for logging in this package.
28+
var linodeclusterlog = logf.Log.WithName("linodecluster-resource")
29+
30+
// SetupLinodeClusterWebhookWithManager registers the webhook for LinodeCluster in the manager.
31+
func SetupLinodeClusterWebhookWithManager(mgr ctrl.Manager) error {
32+
return ctrl.NewWebhookManagedBy(mgr).For(&infrastructurev1beta1.LinodeCluster{}).
33+
Complete()
34+
}
35+
36+
// TODO(user): EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright 2023 Akamai Technologies, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
. "github.com/onsi/ginkgo/v2"
21+
. "github.com/onsi/gomega"
22+
23+
infrastructurev1beta1 "github.com/linode/cluster-api-provider-linode/api/v1beta1"
24+
// TODO (user): Add any additional imports if needed
25+
)
26+
27+
var _ = Describe("LinodeCluster Webhook", func() {
28+
var (
29+
obj *infrastructurev1beta1.LinodeCluster
30+
oldObj *infrastructurev1beta1.LinodeCluster
31+
)
32+
33+
BeforeEach(func() {
34+
obj = &infrastructurev1beta1.LinodeCluster{}
35+
oldObj = &infrastructurev1beta1.LinodeCluster{}
36+
Expect(oldObj).NotTo(BeNil(), "Expected oldObj to be initialized")
37+
Expect(obj).NotTo(BeNil(), "Expected obj to be initialized")
38+
// TODO (user): Add any setup logic common to all tests
39+
})
40+
41+
AfterEach(func() {
42+
// TODO (user): Add any teardown logic common to all tests
43+
})
44+
45+
Context("When creating LinodeCluster under Conversion Webhook", func() {
46+
// TODO (user): Add logic to convert the object to the desired version and verify the conversion
47+
// Example:
48+
// It("Should convert the object correctly", func() {
49+
// convertedObj := &infrastructurev1beta1.LinodeCluster{}
50+
// Expect(obj.ConvertTo(convertedObj)).To(Succeed())
51+
// Expect(convertedObj).ToNot(BeNil())
52+
// })
53+
})
54+
55+
})
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2023 Akamai Technologies, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
ctrl "sigs.k8s.io/controller-runtime"
21+
logf "sigs.k8s.io/controller-runtime/pkg/log"
22+
23+
infrastructurev1beta1 "github.com/linode/cluster-api-provider-linode/api/v1beta1"
24+
)
25+
26+
// nolint:unused
27+
// log is for logging in this package.
28+
var linodemachinelog = logf.Log.WithName("linodemachine-resource")
29+
30+
// SetupLinodeMachineWebhookWithManager registers the webhook for LinodeMachine in the manager.
31+
func SetupLinodeMachineWebhookWithManager(mgr ctrl.Manager) error {
32+
return ctrl.NewWebhookManagedBy(mgr).For(&infrastructurev1beta1.LinodeMachine{}).
33+
Complete()
34+
}
35+
36+
// TODO(user): EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!

0 commit comments

Comments
 (0)