Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Schroeder <97968850+schroeder-paul@users.noreply.github.com>
  • Loading branch information
schroeder-paul committed Jan 27, 2022
1 parent 718c4a0 commit 6afa12f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
11 changes: 3 additions & 8 deletions apis/system/v1alpha1/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,8 @@ type SystemList struct {

// HasLabels whether the system has labels
func (in SystemParameters) HasLabels() bool {
switch {
case strings.HasPrefix(in.Type, "kubernetes"):
// so far only handle labels for kubernetes*
return true
}

return false
// so far only handle labels for kubernetes*
return strings.HasPrefix(in.Type, "kubernetes")
}

// GetAssetTypes gets available asset types
Expand All @@ -123,7 +118,7 @@ func (in SystemParameters) GetAssetTypes() []string {
return []string{}
}

// HasAssets whether the system available assets
// HasAssets whether the system has available assets
func (in SystemParameters) HasAssets() bool {
return len(in.GetAssetTypes()) > 0
}
22 changes: 11 additions & 11 deletions pkg/controller/system/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"context"
"fmt"

"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -61,19 +62,8 @@ const (
errGetLabelsInvalidResponse = "get system labels returned an unexpected response"
errCompareLabels = "cannot compare labels"
errUpdateLabels = "cannotUpdateLabels"
errSystemNotSupported = "system not supported"
)

type connector struct {
kube client.Client
newClientFn func(transport runtime.ClientTransport, formats strfmt.Registry) *styra.StyraAPI
}

type external struct {
client *styra.StyraAPI
kube client.Client
}

// SetupSystem adds a controller that reconciles Systems.
func SetupSystem(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) error {
name := managed.ControllerName(v1alpha1.SystemGroupKind)
Expand All @@ -93,6 +83,16 @@ func SetupSystem(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter) e
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name)))))
}

type connector struct {
kube client.Client
newClientFn func(transport runtime.ClientTransport, formats strfmt.Registry) *styra.StyraAPI
}

type external struct {
client *styra.StyraAPI
kube client.Client
}

func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.ExternalClient, error) {
_, ok := mg.(*v1alpha1.System)
if !ok {
Expand Down
27 changes: 15 additions & 12 deletions pkg/controller/system/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ import (
var (
errBoom = errors.New("boom")

helmValuesAssetType = "helm-values"
helmValuesConnectionDetailsKey = "helmValues"

testSystemID = "testsystem"
testSystemName = "testname"
testType = "kubernetes:test"
Expand Down Expand Up @@ -150,7 +153,7 @@ func TestObserve(t *testing.T) {
}, nil)
mcs.EXPECT().
GetAsset(&systems.GetAssetParams{
Assettype: "helm-values",
Assettype: helmValuesAssetType,
System: testSystemID,
Context: context.Background(),
}, &bytes.Buffer{}, gomock.Any()).
Expand Down Expand Up @@ -229,7 +232,7 @@ func TestObserve(t *testing.T) {
ResourceExists: true,
ResourceUpToDate: true,
ConnectionDetails: managed.ConnectionDetails{
"helmValues": []byte(testAsset),
helmValuesConnectionDetailsKey: []byte(testAsset),
},
},
},
Expand All @@ -256,7 +259,7 @@ func TestObserve(t *testing.T) {
}, nil)
mcs.EXPECT().
GetAsset(&systems.GetAssetParams{
Assettype: "helm-values",
Assettype: helmValuesAssetType,
System: testSystemID,
Context: context.Background(),
}, &bytes.Buffer{}, gomock.Any()).
Expand Down Expand Up @@ -324,7 +327,7 @@ func TestObserve(t *testing.T) {
ResourceUpToDate: true,
ResourceLateInitialized: true,
ConnectionDetails: managed.ConnectionDetails{
"helmValues": []byte(testAsset),
helmValuesConnectionDetailsKey: []byte(testAsset),
},
},
},
Expand All @@ -351,7 +354,7 @@ func TestObserve(t *testing.T) {
}, nil)
mcs.EXPECT().
GetAsset(&systems.GetAssetParams{
Assettype: "helm-values",
Assettype: helmValuesAssetType,
System: testSystemID,
Context: context.Background(),
}, &bytes.Buffer{}, gomock.Any()).
Expand Down Expand Up @@ -426,7 +429,7 @@ func TestObserve(t *testing.T) {
ResourceExists: true,
ResourceUpToDate: false,
ConnectionDetails: managed.ConnectionDetails{
"helmValues": []byte(testAsset),
helmValuesConnectionDetailsKey: []byte(testAsset),
},
},
},
Expand Down Expand Up @@ -535,7 +538,7 @@ func TestObserve(t *testing.T) {
}, nil)
mcs.EXPECT().
GetAsset(&systems.GetAssetParams{
Assettype: "helm-values",
Assettype: helmValuesAssetType,
System: testSystemID,
Context: context.Background(),
}, &bytes.Buffer{}, gomock.Any()).
Expand Down Expand Up @@ -1278,7 +1281,7 @@ func TestGetConnectionDetails(t *testing.T) {
Systems: withMockSystem(t, func(mcs *mocksystem.MockClientService) {
mcs.EXPECT().
GetAsset(&systems.GetAssetParams{
Assettype: "helm-values",
Assettype: helmValuesAssetType,
System: testSystemID,
Context: context.Background(),
}, &bytes.Buffer{}, gomock.Any()).
Expand All @@ -1297,7 +1300,7 @@ func TestGetConnectionDetails(t *testing.T) {
},
want: want{
managed.ConnectionDetails{
"helmValues": {0x74, 0x65, 0x73, 0x74, 0x2d, 0x61, 0x73, 0x73, 0x65, 0x74},
helmValuesConnectionDetailsKey: {0x74, 0x65, 0x73, 0x74, 0x2d, 0x61, 0x73, 0x73, 0x65, 0x74},
},
nil,
},
Expand All @@ -1308,7 +1311,7 @@ func TestGetConnectionDetails(t *testing.T) {
Systems: withMockSystem(t, func(mcs *mocksystem.MockClientService) {
mcs.EXPECT().
GetAsset(&systems.GetAssetParams{
Assettype: "helm-values",
Assettype: helmValuesAssetType,
System: testSystemID,
Context: context.Background(),
}, &bytes.Buffer{}, gomock.Any()).
Expand All @@ -1327,7 +1330,7 @@ func TestGetConnectionDetails(t *testing.T) {
},
want: want{
managed.ConnectionDetails{
"helmValues": {0x74, 0x65, 0x73, 0x74, 0x2d, 0x61, 0x73, 0x73, 0x65, 0x74},
helmValuesConnectionDetailsKey: {0x74, 0x65, 0x73, 0x74, 0x2d, 0x61, 0x73, 0x73, 0x65, 0x74},
},
nil,
},
Expand All @@ -1353,7 +1356,7 @@ func TestGetConnectionDetails(t *testing.T) {
Systems: withMockSystem(t, func(mcs *mocksystem.MockClientService) {
mcs.EXPECT().
GetAsset(&systems.GetAssetParams{
Assettype: "helm-values",
Assettype: helmValuesAssetType,
System: testSystemID,
Context: context.Background(),
}, &bytes.Buffer{}, gomock.Any()).
Expand Down

0 comments on commit 6afa12f

Please sign in to comment.