Skip to content

Commit

Permalink
Be more informative
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenlj committed Sep 10, 2024
1 parent 094a314 commit b4cec4a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
9 changes: 9 additions & 0 deletions pkg/option/option.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package option

import "fmt"

type Option[T any] struct {
isSome bool
value T
Expand All @@ -25,6 +27,13 @@ func (o Option[T]) Do(f func(T)) {
}
}

func (o Option[T]) String() string {
if o.isSome {
return fmt.Sprintf("%v", o.value)
}
return ""
}

func None[T any]() Option[T] {
return Option[T]{}
}
Expand Down
9 changes: 2 additions & 7 deletions pkg/postgres/migrate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,8 @@ type InstanceConfig struct {
Type option.Option[string]
}

func NewInstanceConfig() InstanceConfig {
return InstanceConfig{
InstanceName: option.None[string](),
Tier: option.None[string](),
DiskSize: option.None[int](),
Type: option.None[string](),
}
func (ic *InstanceConfig) String() string {
return fmt.Sprintf("Name: %v\nTier: %v\nDiskSize: %v\nType: %v\n", ic.InstanceName, ic.Tier, ic.DiskSize, ic.Type)
}

func (ic *InstanceConfig) Resolve(ctx context.Context, client ctrl.Client, appName, namespace string) error {
Expand Down
7 changes: 6 additions & 1 deletion pkg/postgres/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,27 @@ func NewMigrator(client ctrl.Client, cfg Config) *Migrator {
}

func (m *Migrator) Setup(ctx context.Context) error {
fmt.Println("Resolving target instance config")
err := m.cfg.Target.Resolve(ctx, m.client, m.cfg.AppName, m.cfg.Namespace)
if err != nil {
return err
}
fmt.Printf("Resolved target:\n%s\n", m.cfg.Target.String())

fmt.Println("Resolving source instance config")
err = m.cfg.Source.Resolve(ctx, m.client, m.cfg.AppName, m.cfg.Namespace)
if err != nil {
return err
}
fmt.Printf("Resolved source:\n%s\n", m.cfg.Source.String())

fmt.Println("Creating ConfigMap")
cfgMap := m.cfg.CreateConfigMap()

err = m.client.Create(ctx, &cfgMap)
if err != nil {
return fmt.Errorf("failed to create ConfigMap: %w", err)
}

fmt.Println("TODO: Do more stuff")
return fmt.Errorf("TODO: Do more stuff")
}

0 comments on commit b4cec4a

Please sign in to comment.