Skip to content

Commit

Permalink
feat(models): add conditions method to aiven managed object
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov committed Nov 21, 2023
1 parent 3742030 commit 871a79d
Show file tree
Hide file tree
Showing 23 changed files with 125 additions and 13 deletions.
6 changes: 6 additions & 0 deletions api/v1alpha1/cassandra_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ type Cassandra struct {
Status ServiceStatus `json:"status,omitempty"`
}

var _ AivenManagedObject = &Cassandra{}

func (in *Cassandra) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}

func (in *Cassandra) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

func (in *Cassandra) GetRefs() []*ResourceReferenceObject {
return in.Spec.GetRefs(in.GetNamespace())
}
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/clickhouse_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,16 @@ type ClickhouseList struct {
Items []Clickhouse `json:"items"`
}

var _ AivenManagedObject = &Clickhouse{}

func (in *Clickhouse) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}

func (in *Clickhouse) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

func (in *Clickhouse) GetRefs() []*ResourceReferenceObject {
return in.Spec.GetRefs(in.GetNamespace())
}
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/clickhouseuser_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@ type ClickhouseUser struct {
Status ClickhouseUserStatus `json:"status,omitempty"`
}

var _ AivenManagedObject = &ClickhouseUser{}

func (in *ClickhouseUser) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}

func (in *ClickhouseUser) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

func (in *ClickhouseUser) GetConnInfoSecretTarget() ConnInfoSecretTarget {
return in.Spec.ConnInfoSecretTarget
}
Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,10 @@ type ServiceIntegrationItem struct {
// +kubebuilder:validation:MaxLength=64
SourceServiceName string `json:"sourceServiceName"`
}

type AivenManagedObject interface {
client.Object

AuthSecretRef() *AuthSecretReference
Conditions() *[]metav1.Condition
}
6 changes: 6 additions & 0 deletions api/v1alpha1/connectionpool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@ type ConnectionPool struct {
Status ConnectionPoolStatus `json:"status,omitempty"`
}

var _ AivenManagedObject = &ConnectionPool{}

func (in *ConnectionPool) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}

func (in *ConnectionPool) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

func (in *ConnectionPool) GetConnInfoSecretTarget() ConnInfoSecretTarget {
return in.Spec.ConnInfoSecretTarget
}
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/database_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,14 @@ type Database struct {
Status DatabaseStatus `json:"status,omitempty"`
}

var _ AivenManagedObject = &Database{}

func (in *Database) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}
func (in *Database) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

// +kubebuilder:object:root=true

Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/grafana_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ type Grafana struct {
Status ServiceStatus `json:"status,omitempty"`
}

var _ AivenManagedObject = &Grafana{}

func (in *Grafana) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}

func (in *Grafana) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

func (in *Grafana) GetRefs() []*ResourceReferenceObject {
return in.Spec.GetRefs(in.GetNamespace())
}
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/kafka_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,16 @@ type Kafka struct {
Status ServiceStatus `json:"status,omitempty"`
}

var _ AivenManagedObject = &Kafka{}

func (in *Kafka) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}

func (in *Kafka) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

func (in *Kafka) GetRefs() []*ResourceReferenceObject {
return in.Spec.GetRefs(in.GetNamespace())
}
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/kafkaacl_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,16 @@ type KafkaACL struct {
Status KafkaACLStatus `json:"status,omitempty"`
}

var _ AivenManagedObject = &KafkaACL{}

func (in *KafkaACL) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}

func (in *KafkaACL) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

// +kubebuilder:object:root=true

// KafkaACLList contains a list of KafkaACL
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/kafkaconnect_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ type KafkaConnect struct {
Status ServiceStatus `json:"status,omitempty"`
}

var _ AivenManagedObject = &KafkaConnect{}

func (in *KafkaConnect) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}

func (in *KafkaConnect) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

func (in *KafkaConnect) GetRefs() []*ResourceReferenceObject {
return in.Spec.GetRefs(in.GetNamespace())
}
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/kafkaconnector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,16 @@ type KafkaConnector struct {
Status KafkaConnectorStatus `json:"status,omitempty"`
}

var _ AivenManagedObject = &KafkaConnector{}

func (in *KafkaConnector) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}

func (in *KafkaConnector) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

//+kubebuilder:object:root=true

// KafkaConnectorList contains a list of KafkaConnector
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/kafkaschema_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,16 @@ type KafkaSchema struct {
Status KafkaSchemaStatus `json:"status,omitempty"`
}

var _ AivenManagedObject = &KafkaSchema{}

func (in *KafkaSchema) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}

func (in *KafkaSchema) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

// +kubebuilder:object:root=true

// KafkaSchemaList contains a list of KafkaSchema
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/kafkatopic_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,16 @@ type KafkaTopic struct {
Status KafkaTopicStatus `json:"status,omitempty"`
}

var _ AivenManagedObject = &KafkaTopic{}

func (in *KafkaTopic) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}

func (in *KafkaTopic) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

// +kubebuilder:object:root=true

// KafkaTopicList contains a list of KafkaTopic
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/mysql_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ type MySQL struct {
Status ServiceStatus `json:"status,omitempty"`
}

var _ AivenManagedObject = &MySQL{}

func (in *MySQL) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}
func (in *MySQL) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

func (in *MySQL) GetRefs() []*ResourceReferenceObject {
return in.Spec.GetRefs(in.GetNamespace())
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/opensearch_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ type OpenSearchList struct {
Items []OpenSearch `json:"items"`
}

var _ AivenManagedObject = &OpenSearch{}

func (in *OpenSearch) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}
func (in *OpenSearch) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

func (in *OpenSearch) GetRefs() []*ResourceReferenceObject {
return in.Spec.GetRefs(in.GetNamespace())
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/postgresql_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ type PostgreSQL struct {
Status ServiceStatus `json:"status,omitempty"`
}

var _ AivenManagedObject = &PostgreSQL{}

func (in *PostgreSQL) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}
func (in *PostgreSQL) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

func (in *PostgreSQL) GetRefs() []*ResourceReferenceObject {
return in.Spec.GetRefs(in.GetNamespace())
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/project_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ type Project struct {
Status ProjectStatus `json:"status,omitempty"`
}

var _ AivenManagedObject = &Project{}

func (in *Project) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}
func (in *Project) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

func (in *Project) GetConnInfoSecretTarget() ConnInfoSecretTarget {
return in.Spec.ConnInfoSecretTarget
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/projectvpc_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ type ProjectVPC struct {
Status ProjectVPCStatus `json:"status,omitempty"`
}

var _ AivenManagedObject = &ProjectVPC{}

func (in *ProjectVPC) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}
func (in *ProjectVPC) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

// +kubebuilder:object:root=true

Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/redis_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ type Redis struct {
Status ServiceStatus `json:"status,omitempty"`
}

var _ AivenManagedObject = &Redis{}

func (in *Redis) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}
func (in *Redis) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

func (in *Redis) GetRefs() []*ResourceReferenceObject {
return in.Spec.GetRefs(in.GetNamespace())
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/serviceintegration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,14 @@ type ServiceIntegration struct {
Status ServiceIntegrationStatus `json:"status,omitempty"`
}

var _ AivenManagedObject = &ServiceIntegration{}

func (in *ServiceIntegration) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}
func (in *ServiceIntegration) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

func (in *ServiceIntegration) GetUserConfig() (any, error) {
configs := map[string]any{
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/serviceuser_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ type ServiceUser struct {
Status ServiceUserStatus `json:"status,omitempty"`
}

var _ AivenManagedObject = &ServiceUser{}

func (in *ServiceUser) AuthSecretRef() *AuthSecretReference {
return in.Spec.AuthSecretRef
}
func (in *ServiceUser) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

func (in *ServiceUser) GetConnInfoSecretTarget() ConnInfoSecretTarget {
return in.Spec.ConnInfoSecretTarget
Expand Down
8 changes: 1 addition & 7 deletions controllers/basic_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ type (
checkPreconditions(ctx context.Context, avn *aiven.Client, obj client.Object) (bool, error)
}

aivenManagedObject interface {
client.Object

AuthSecretRef() *v1alpha1.AuthSecretReference
}

// refsObject returns references to dependent resources
refsObject interface {
client.Object
Expand Down Expand Up @@ -103,7 +97,7 @@ const (
// +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="",resources=events,verbs=create;patch

func (c *Controller) reconcileInstance(ctx context.Context, req ctrl.Request, h Handlers, o aivenManagedObject) (ctrl.Result, error) {
func (c *Controller) reconcileInstance(ctx context.Context, req ctrl.Request, h Handlers, o v1alpha1.AivenManagedObject) (ctrl.Result, error) {
if err := c.Get(ctx, req.NamespacedName, o); err != nil {
return ctrl.Result{}, client.IgnoreNotFound(err)
}
Expand Down
12 changes: 6 additions & 6 deletions controllers/secret_finalizer_gc_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c *SecretFinalizerGCController) SetupWithManager(mgr ctrl.Manager, hasDefa
builder.Watches(
&source.Kind{Type: aivenManagedTypes[i]},
handler.EnqueueRequestsFromMapFunc(func(a client.Object) []reconcile.Request {
ao := a.(aivenManagedObject)
ao := a.(v1alpha1.AivenManagedObject)
if auth := ao.AuthSecretRef(); auth != nil {
return []reconcile.Request{
{
Expand Down Expand Up @@ -126,11 +126,11 @@ func (c *SecretFinalizerGCController) knownListTypes() []client.ObjectList {
return res
}

func (c *SecretFinalizerGCController) knownInstanceTypes() []aivenManagedObject {
res := make([]aivenManagedObject, 0)
func (c *SecretFinalizerGCController) knownInstanceTypes() []v1alpha1.AivenManagedObject {
res := make([]v1alpha1.AivenManagedObject, 0)

for _, t := range c.Scheme().KnownTypes(v1alpha1.GroupVersion) {
if obj, ok := reflect.New(t).Interface().(aivenManagedObject); ok {
if obj, ok := reflect.New(t).Interface().(v1alpha1.AivenManagedObject); ok {
res = append(res, obj)
}
}
Expand All @@ -156,15 +156,15 @@ const (

// secretRefIndexFunc indexes the client token secret names of aiven managed objects
func secretRefIndexFunc(o client.Object) []string {
if aivenObj, ok := o.(aivenManagedObject); ok {
if aivenObj, ok := o.(v1alpha1.AivenManagedObject); ok {
if auth := aivenObj.AuthSecretRef(); auth != nil {
return []string{auth.Name}
}
}
return nil
}

func indexClientSecretRefFields(ctx context.Context, mgr ctrl.Manager, objs ...aivenManagedObject) error {
func indexClientSecretRefFields(ctx context.Context, mgr ctrl.Manager, objs ...v1alpha1.AivenManagedObject) error {
for i := range objs {
if err := mgr.GetFieldIndexer().IndexField(ctx, objs[i], secretRefIndexKey, secretRefIndexFunc); err != nil {
return err
Expand Down

0 comments on commit 871a79d

Please sign in to comment.