Skip to content

Commit

Permalink
feat: add new providers package
Browse files Browse the repository at this point in the history
  • Loading branch information
bfabricio committed Feb 18, 2025
1 parent 85eec89 commit a175599
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pkg/providers/aws.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package providers

import (
"context"
"github.com/spf13/viper"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type AWSProvider struct {
}

func NewAWSProvider(k8sClient client.Client, config *viper.Viper) *AWSProvider {
return &AWSProvider{}
}

func (p *AWSProvider) CreateDatabase(ctx context.Context, spec DatabaseSpec) error {
return nil
}

func (p *AWSProvider) DeleteDatabase(ctx context.Context, name string) error {
return nil
}

func (p *AWSProvider) GetDatabase(ctx context.Context, name string) (*DatabaseSpec, error) {
return nil, nil
}
26 changes: 26 additions & 0 deletions pkg/providers/cloudnative_pg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package providers

import (
"context"
"github.com/spf13/viper"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type CloudNativePGProvider struct {
}

func NewCloudNativePGProvider(k8sClient client.Client, config *viper.Viper) *CloudNativePGProvider {
return &CloudNativePGProvider{}
}

func (p *CloudNativePGProvider) CreateDatabase(ctx context.Context, spec DatabaseSpec) error {
return nil
}

func (p *CloudNativePGProvider) DeleteDatabase(ctx context.Context, name string) error {
return nil
}

func (p *CloudNativePGProvider) GetDatabase(ctx context.Context, name string) (*DatabaseSpec, error) {
return nil, nil
}
26 changes: 26 additions & 0 deletions pkg/providers/gcp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package providers

import (
"context"
"github.com/spf13/viper"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type GCPProvider struct {
}

func NewGCPProvider(k8sClient client.Client, config *viper.Viper) *GCPProvider {
return &GCPProvider{}
}

func (p *GCPProvider) CreateDatabase(ctx context.Context, spec DatabaseSpec) error {
return nil
}

func (p *GCPProvider) DeleteDatabase(ctx context.Context, name string) error {
return nil
}

func (p *GCPProvider) GetDatabase(ctx context.Context, name string) (*DatabaseSpec, error) {
return nil, nil
}
57 changes: 57 additions & 0 deletions pkg/providers/providers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package providers

import (
"context"
"fmt"
v1 "github.com/infobloxopen/db-controller/api/v1"
"github.com/infobloxopen/db-controller/pkg/hostparams"
"github.com/spf13/viper"

"sigs.k8s.io/controller-runtime/pkg/client"
)

// DatabaseSpec defines the required parameters to provision a database using any provider.
type DatabaseSpec struct {
ProviderResourceName string
DbType v1.DatabaseType
SharedDBHost bool
MasterConnInfo v1.DatabaseClaimConnectionInfo
TempSecret string
HostParams hostparams.HostParams
EnableReplicationRole bool
EnableSuperUser bool
EnablePerfInsight bool
EnableCloudwatchLogsExport []*string
BackupRetentionDays int64
CACertificateIdentifier string

Tags v1.Tag
Labels map[string]string
PreferredMaintenanceWindow *string
BackupPolicy string
}

// Provider is an interface that abstracts provider-specific logic.
type Provider interface {
// CreateDatabase provisions a new database instance.
CreateDatabase(ctx context.Context, spec DatabaseSpec) error
// DeleteDatabase deprovisions an existing database instance.
DeleteDatabase(ctx context.Context, name string) error
// GetDatabase retrieves the current status of a database instance.
GetDatabase(ctx context.Context, name string) (*DatabaseSpec, error)
}

// NewProvider returns a concrete provider implementation based on the given provider name.
func NewProvider(config *viper.Viper, k8sClient client.Client) (Provider, error) {
cloud := config.GetString("cloud")
switch cloud {
case "aws":
return NewAWSProvider(k8sClient, config), nil
case "gcp":
return NewGCPProvider(k8sClient, config), nil
case "cloudnative-pg":
return nil, nil
default:
return nil, fmt.Errorf("unsupported provider for cloud: %s", cloud)
}
}

0 comments on commit a175599

Please sign in to comment.