Skip to content

Commit d4bf672

Browse files
author
rriski
authored
feat: add Flink kind (#848)
1 parent 47fab8c commit d4bf672

29 files changed

+1953
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
minimum ~~`1`~~`0`
5252
- Change `Cassandra` field `userConfig.cassandra_version`: enum remove `4`
5353
- Change `PostgreSQL` field `userConfig.pg_version`: enum remove `12`
54+
- Add kind: `Flink`
5455

5556
## v0.25.0 - 2024-09-19
5657

PROJECT

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,17 @@ resources:
291291
defaulting: true
292292
validation: true
293293
webhookVersion: v1
294+
- api:
295+
crdVersion: v1
296+
namespaced: true
297+
controller: true
298+
domain: aiven.io
299+
kind: Flink
300+
path: github.com/aiven/aiven-operator/api/v1alpha1
301+
version: v1alpha1
302+
webhooks:
303+
conversion: true
304+
defaulting: true
305+
validation: true
306+
webhookVersion: v1
294307
version: "3"

api/v1alpha1/flink_types.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (c) 2024 Aiven, Helsinki, Finland. https://aiven.io/
2+
3+
package v1alpha1
4+
5+
import (
6+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
7+
8+
flinkuserconfig "github.com/aiven/aiven-operator/api/v1alpha1/userconfig/service/flink"
9+
)
10+
11+
// FlinkSpec defines the desired state of Flink
12+
type FlinkSpec struct {
13+
ServiceCommonSpec `json:",inline"`
14+
15+
// Cassandra specific user configuration options
16+
UserConfig *flinkuserconfig.FlinkUserConfig `json:"userConfig,omitempty"`
17+
}
18+
19+
// Flink is the Schema for the flinks API.
20+
// Info "Exposes secret keys": `FLINK_HOST`, `FLINK_PORT`, `FLINK_USER`, `FLINK_PASSWORD`, `FLINK_URI`, `FLINK_HOSTS`
21+
// +kubebuilder:object:root=true
22+
// +kubebuilder:subresource:status
23+
// +kubebuilder:printcolumn:name="Project",type="string",JSONPath=".spec.project"
24+
// +kubebuilder:printcolumn:name="Region",type="string",JSONPath=".spec.cloudName"
25+
// +kubebuilder:printcolumn:name="Plan",type="string",JSONPath=".spec.plan"
26+
// +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state"
27+
type Flink struct {
28+
metav1.TypeMeta `json:",inline"`
29+
metav1.ObjectMeta `json:"metadata,omitempty"`
30+
31+
Spec FlinkSpec `json:"spec,omitempty"`
32+
Status ServiceStatus `json:"status,omitempty"`
33+
}
34+
35+
var _ AivenManagedObject = &Flink{}
36+
37+
func (in *Flink) AuthSecretRef() *AuthSecretReference {
38+
return in.Spec.AuthSecretRef
39+
}
40+
41+
func (in *Flink) Conditions() *[]metav1.Condition {
42+
return &in.Status.Conditions
43+
}
44+
45+
func (in *Flink) NoSecret() bool {
46+
return in.Spec.ConnInfoSecretTargetDisabled != nil && *in.Spec.ConnInfoSecretTargetDisabled
47+
}
48+
49+
func (in *Flink) GetRefs() []*ResourceReferenceObject {
50+
return in.Spec.GetRefs(in.GetNamespace())
51+
}
52+
53+
func (in *Flink) GetConnInfoSecretTarget() ConnInfoSecretTarget {
54+
return in.Spec.ConnInfoSecretTarget
55+
}
56+
57+
//+kubebuilder:object:root=true
58+
59+
// FlinkList contains a list of Flink
60+
type FlinkList struct {
61+
metav1.TypeMeta `json:",inline"`
62+
metav1.ListMeta `json:"metadata,omitempty"`
63+
Items []Flink `json:"items"`
64+
}
65+
66+
func init() {
67+
SchemeBuilder.Register(&Flink{}, &FlinkList{})
68+
}

api/v1alpha1/flink_webhook.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (c) 2024 Aiven, Helsinki, Finland. https://aiven.io/
2+
3+
package v1alpha1
4+
5+
import (
6+
"errors"
7+
8+
"k8s.io/apimachinery/pkg/runtime"
9+
ctrl "sigs.k8s.io/controller-runtime"
10+
logf "sigs.k8s.io/controller-runtime/pkg/log"
11+
"sigs.k8s.io/controller-runtime/pkg/webhook"
12+
)
13+
14+
// log is for logging in this package.
15+
var flinklog = logf.Log.WithName("flink-resource")
16+
17+
func (in *Flink) SetupWebhookWithManager(mgr ctrl.Manager) error {
18+
return ctrl.NewWebhookManagedBy(mgr).
19+
For(in).
20+
Complete()
21+
}
22+
23+
//+kubebuilder:webhook:path=/mutate-aiven-io-v1alpha1-flink,mutating=true,failurePolicy=fail,sideEffects=None,groups=aiven.io,resources=flinks,verbs=create;update,versions=v1alpha1,name=mflink.kb.io,admissionReviewVersions=v1
24+
25+
var _ webhook.Defaulter = &Flink{}
26+
27+
func (in *Flink) Default() {
28+
flinklog.Info("default", "name", in.Name)
29+
}
30+
31+
//+kubebuilder:webhook:verbs=create;update;delete,path=/validate-aiven-io-v1alpha1-flink,mutating=false,failurePolicy=fail,groups=aiven.io,resources=flinks,versions=v1alpha1,name=vflink.kb.io,sideEffects=none,admissionReviewVersions=v1
32+
33+
var _ webhook.Validator = &Flink{}
34+
35+
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
36+
func (in *Flink) ValidateCreate() error {
37+
flinklog.Info("validate create", "name", in.Name)
38+
39+
return in.Spec.Validate()
40+
}
41+
42+
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
43+
func (in *Flink) ValidateUpdate(old runtime.Object) error {
44+
flinklog.Info("validate update", "name", in.Name)
45+
return in.Spec.Validate()
46+
}
47+
48+
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
49+
func (in *Flink) ValidateDelete() error {
50+
flinklog.Info("validate delete", "name", in.Name)
51+
52+
if in.Spec.TerminationProtection != nil && *in.Spec.TerminationProtection {
53+
return errors.New("cannot delete Flink service, termination protection is on")
54+
}
55+
56+
if in.Spec.ProjectVPCID != "" && in.Spec.ProjectVPCRef != nil {
57+
return errors.New("cannot use both projectVpcId and projectVPCRef")
58+
}
59+
60+
return nil
61+
}

api/v1alpha1/setup_webhooks.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ func SetupWebhooks(mgr ctrl.Manager) error {
1616
if err := (&Database{}).SetupWebhookWithManager(mgr); err != nil {
1717
return fmt.Errorf("webhook Database: %w", err)
1818
}
19+
if err := (&Flink{}).SetupWebhookWithManager(mgr); err != nil {
20+
return fmt.Errorf("webhook Flink: %w", err)
21+
}
1922
if err := (&ConnectionPool{}).SetupWebhookWithManager(mgr); err != nil {
2023
return fmt.Errorf("webhook ConnectionPool: %w", err)
2124
}

api/v1alpha1/userconfig/service/flink/flink.go

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha1/userconfig/service/flink/zz_generated.deepcopy.go

Lines changed: 143 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)