Skip to content

Commit

Permalink
🌱 Support disconnected hub.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ortel <jortel@redhat.com>
  • Loading branch information
jortel committed Feb 22, 2023
1 parent 155a78e commit d152631
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 20 deletions.
34 changes: 18 additions & 16 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,27 @@ func main() {
if err != nil {
panic(err)
}
//
// k8s scheme.
err = buildScheme()
if err != nil {
return
}
//
// Add controller.
addonManager, err := addonManager(db)
if err != nil {
return
}
go func() {
err = addonManager.Start(make(<-chan struct{}))
if !Settings.Disconnected {
//
// k8s scheme.
err = buildScheme()
if err != nil {
err = liberr.Wrap(err)
return
}
}()
//
// Add controller.
addonManager, err := addonManager(db)
if err != nil {
return
}
go func() {
err = addonManager.Start(make(<-chan struct{}))
if err != nil {
err = liberr.Wrap(err)
return
}
}()
}
//
// k8s client.
client, err := k8s.NewClient()
Expand Down
36 changes: 36 additions & 0 deletions k8s/client.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package k8s

import (
"context"
liberr "github.com/konveyor/controller/pkg/error"
"github.com/konveyor/tackle2-hub/settings"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
)

var Settings = &settings.Settings

//
// NewClient builds new k8s client.
func NewClient() (newClient client.Client, err error) {
if Settings.Disconnected {
newClient = &FakeClient{}
return
}
cfg, _ := config.GetConfig()
newClient, err = client.New(
cfg,
Expand All @@ -21,3 +30,30 @@ func NewClient() (newClient client.Client, err error) {
}
return
}

type FakeClient struct {
}

func (r *FakeClient) Get(_ context.Context, _ client.ObjectKey, _ runtime.Object) (err error) {
return
}

func (r *FakeClient) List(_ context.Context, _ *client.ListOptions, _ runtime.Object) (err error) {
return
}

func (r *FakeClient) Create(_ context.Context, _ runtime.Object) (err error) {
return
}

func (r *FakeClient) Delete(_ context.Context, _ runtime.Object, _ ...client.DeleteOptionFunc) (err error) {
return
}

func (r *FakeClient) Update(_ context.Context, _ runtime.Object) (err error) {
return
}

func (r *FakeClient) Status() (w client.StatusWriter) {
return
}
12 changes: 8 additions & 4 deletions settings/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
EnvDevelopment = "DEVELOPMENT"
EnvFileTTL = "FILE_TTL"
EnvAppName = "APP_NAME"
EnvDisconnected = "DISCONNECTED"
)

type Hub struct {
Expand Down Expand Up @@ -72,6 +73,8 @@ type Hub struct {
Development bool
// Product - deployed as product.
Product bool
// Disconnected indicates no cluster.
Disconnected bool
}

func (r *Hub) Load() (err error) {
Expand Down Expand Up @@ -161,8 +164,6 @@ func (r *Hub) Load() (err error) {
if found {
b, _ := strconv.ParseBool(s)
r.Development = b
} else {
r.Development = false
}
s, found = os.LookupEnv(EnvFileTTL)
if found {
Expand All @@ -174,8 +175,11 @@ func (r *Hub) Load() (err error) {
s, found = os.LookupEnv(EnvAppName)
if found {
r.Product = !(s == "" || s == "tackle")
} else {
r.Product = false
}
s, found = os.LookupEnv(EnvDisconnected)
if found {
b, _ := strconv.ParseBool(s)
r.Disconnected = b
}

return
Expand Down

0 comments on commit d152631

Please sign in to comment.