Skip to content

Commit

Permalink
make kind string values consistent across backend using flux controll…
Browse files Browse the repository at this point in the history
…er types
  • Loading branch information
joshri committed Sep 22, 2022
1 parent 2d7de61 commit d233509
Show file tree
Hide file tree
Showing 18 changed files with 244 additions and 292 deletions.
35 changes: 3 additions & 32 deletions api/core/core.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,7 @@
"name": "involvedObject.kind",
"in": "query",
"required": false,
"type": "string",
"enum": [
"GitRepository",
"Bucket",
"HelmRepository",
"HelmChart",
"Kustomization",
"HelmRelease",
"Cluster",
"OCIRepository",
"Provider",
"Alert"
],
"default": "GitRepository"
"type": "string"
},
{
"name": "involvedObject.name",
Expand Down Expand Up @@ -510,7 +497,7 @@
"type": "object",
"properties": {
"kind": {
"$ref": "#/definitions/v1Kind"
"type": "string"
},
"name": {
"type": "string"
Expand Down Expand Up @@ -754,22 +741,6 @@
},
"title": "GroupVersionKind represents an objects Kubernetes API type data"
},
"v1Kind": {
"type": "string",
"enum": [
"GitRepository",
"Bucket",
"HelmRepository",
"HelmChart",
"Kustomization",
"HelmRelease",
"Cluster",
"OCIRepository",
"Provider",
"Alert"
],
"default": "GitRepository"
},
"v1ListError": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -910,7 +881,7 @@
"type": "object",
"properties": {
"kind": {
"$ref": "#/definitions/v1Kind"
"type": "string"
},
"name": {
"type": "string"
Expand Down
4 changes: 2 additions & 2 deletions api/core/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ enum HelmRepositoryType {
};

message ObjectRef {
Kind kind = 1;
string kind = 1;
string name = 2;
string namespace = 3;
}

message ClusteredObjRef {
Kind kind = 1;
string kind = 1;
string name = 2;
string namespace = 3;
string clusterName = 4;
Expand Down
16 changes: 8 additions & 8 deletions core/clustersmngr/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestClientGet(t *testing.T) {
},
Spec: kustomizev1.KustomizationSpec{
SourceRef: kustomizev1.CrossNamespaceSourceReference{
Kind: "GitRepository",
Kind: sourcev1.GitRepositoryKind,
},
},
}
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestClientClusteredList(t *testing.T) {
},
Spec: kustomizev1.KustomizationSpec{
SourceRef: kustomizev1.CrossNamespaceSourceReference{
Kind: "GitRepository",
Kind: sourcev1.GitRepositoryKind,
},
},
}
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestClientClusteredListPagination(t *testing.T) {
},
Spec: kustomizev1.KustomizationSpec{
SourceRef: kustomizev1.CrossNamespaceSourceReference{
Kind: "GitRepository",
Kind: sourcev1.GitRepositoryKind,
},
},
}
Expand Down Expand Up @@ -294,7 +294,7 @@ func TestClientList(t *testing.T) {
},
Spec: kustomizev1.KustomizationSpec{
SourceRef: kustomizev1.CrossNamespaceSourceReference{
Kind: "GitRepository",
Kind: sourcev1.GitRepositoryKind,
},
},
}
Expand Down Expand Up @@ -331,7 +331,7 @@ func TestClientCreate(t *testing.T) {
},
Spec: kustomizev1.KustomizationSpec{
SourceRef: kustomizev1.CrossNamespaceSourceReference{
Kind: "GitRepository",
Kind: sourcev1.GitRepositoryKind,
},
},
}
Expand Down Expand Up @@ -366,7 +366,7 @@ func TestClientDelete(t *testing.T) {
},
Spec: kustomizev1.KustomizationSpec{
SourceRef: kustomizev1.CrossNamespaceSourceReference{
Kind: "GitRepository",
Kind: sourcev1.GitRepositoryKind,
},
},
}
Expand Down Expand Up @@ -400,7 +400,7 @@ func TestClientUpdate(t *testing.T) {
Spec: kustomizev1.KustomizationSpec{
Path: "/foo",
SourceRef: kustomizev1.CrossNamespaceSourceReference{
Kind: "GitRepository",
Kind: sourcev1.GitRepositoryKind,
},
},
}
Expand Down Expand Up @@ -442,7 +442,7 @@ func TestClientPatch(t *testing.T) {
Spec: kustomizev1.KustomizationSpec{
Path: "/foo",
SourceRef: kustomizev1.CrossNamespaceSourceReference{
Kind: "GitRepository",
Kind: sourcev1.GitRepositoryKind,
},
},
}
Expand Down
17 changes: 8 additions & 9 deletions core/fluxsync/adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
"github.com/fluxcd/pkg/apis/meta"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
pb "github.com/weaveworks/weave-gitops/pkg/api/core"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -269,27 +268,27 @@ func (s sRef) Kind() string {
return s.kind
}

func ToReconcileable(kind pb.Kind) (client.ObjectList, Reconcilable, error) {
func ToReconcileable(kind string) (client.ObjectList, Reconcilable, error) {
switch kind {
case pb.Kind_Kustomization:
case kustomizev1.KustomizationKind:
return &kustomizev1.KustomizationList{}, NewReconcileable(&kustomizev1.Kustomization{}), nil

case pb.Kind_HelmRelease:
case helmv2.HelmReleaseKind:
return &helmv2.HelmReleaseList{}, NewReconcileable(&helmv2.HelmRelease{}), nil

case pb.Kind_GitRepository:
case sourcev1.GitRepositoryKind:
return &sourcev1.GitRepositoryList{}, NewReconcileable(&sourcev1.GitRepository{}), nil

case pb.Kind_Bucket:
case sourcev1.BucketKind:
return &sourcev1.GitRepositoryList{}, NewReconcileable(&sourcev1.Bucket{}), nil

case pb.Kind_HelmRepository:
case sourcev1.HelmRepositoryKind:
return &sourcev1.GitRepositoryList{}, NewReconcileable(&sourcev1.HelmRepository{}), nil

case pb.Kind_HelmChart:
case sourcev1.HelmChartKind:
return &sourcev1.GitRepositoryList{}, NewReconcileable(&sourcev1.HelmChart{}), nil

case pb.Kind_OCIRepository:
case sourcev1.OCIRepositoryKind:
return &sourcev1.OCIRepositoryList{}, NewReconcileable(&sourcev1.OCIRepository{}), nil
}

Expand Down
2 changes: 1 addition & 1 deletion core/server/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (cs *coreServer) ListEvents(ctx context.Context, msg *pb.ListEventsRequest)

kind := msg.InvolvedObject.Kind

gvk, err := cs.primaryKinds.Lookup(kind.String())
gvk, err := cs.primaryKinds.Lookup(kind)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "bad request: not a recognized object kind")
}
Expand Down
12 changes: 7 additions & 5 deletions core/server/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"testing"

helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
. "github.com/onsi/gomega"
pb "github.com/weaveworks/weave-gitops/pkg/api/core"
"github.com/weaveworks/weave-gitops/pkg/kube"
Expand Down Expand Up @@ -41,7 +43,7 @@ func TestListEvents(t *testing.T) {
Namespace: ns.Name,
},
InvolvedObject: corev1.ObjectReference{
Kind: "Kustomization",
Kind: kustomizev1.KustomizationKind,
Namespace: ns.Name,
Name: kustomizationObjectName,
},
Expand All @@ -57,7 +59,7 @@ func TestListEvents(t *testing.T) {
Namespace: ns.Name,
},
InvolvedObject: corev1.ObjectReference{
Kind: "HelmRelease",
Kind: helmv2.HelmReleaseKind,
Namespace: ns.Name,
Name: helmObjectName,
},
Expand All @@ -73,7 +75,7 @@ func TestListEvents(t *testing.T) {
Namespace: ns.Name,
},
InvolvedObject: corev1.ObjectReference{
Kind: "Kustomization",
Kind: kustomizev1.KustomizationKind,
Namespace: ns.Name,
Name: "someotherobject",
},
Expand All @@ -91,7 +93,7 @@ func TestListEvents(t *testing.T) {
InvolvedObject: &pb.ObjectRef{
Name: kustomizationObjectName,
Namespace: ns.Name,
Kind: pb.Kind_Kustomization,
Kind: kustomizev1.KustomizationKind,
},
})
g.Expect(err).NotTo(HaveOccurred())
Expand All @@ -105,7 +107,7 @@ func TestListEvents(t *testing.T) {
InvolvedObject: &pb.ObjectRef{
Name: helmObjectName,
Namespace: ns.Name,
Kind: pb.Kind_HelmRelease,
Kind: helmv2.HelmReleaseKind,
},
})
g.Expect(err).NotTo(HaveOccurred())
Expand Down
4 changes: 2 additions & 2 deletions core/server/fluxruntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ func (cs *coreServer) GetReconciledObjects(ctx context.Context, msg *pb.GetRecon
var opts client.MatchingLabels

switch msg.AutomationKind {
case "Kustomization":
case kustomizev1.KustomizationKind:
opts = client.MatchingLabels{
KustomizeNameKey: msg.AutomationName,
KustomizeNamespaceKey: msg.Namespace,
}
case "HelmRelease":
case helmv2.HelmReleaseKind:
opts = client.MatchingLabels{
HelmNameKey: msg.AutomationName,
HelmNamespaceKey: msg.Namespace,
Expand Down
3 changes: 2 additions & 1 deletion core/server/fluxruntime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"testing"

kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
. "github.com/onsi/gomega"
"github.com/weaveworks/weave-gitops/core/clustersmngr"
"github.com/weaveworks/weave-gitops/core/server"
Expand Down Expand Up @@ -71,7 +72,7 @@ func TestGetReconciledObjects(t *testing.T) {
res, err := c.GetReconciledObjects(ctx, &pb.GetReconciledObjectsRequest{
AutomationName: automationName,
Namespace: ns.Name,
AutomationKind: "Kustomization",
AutomationKind: kustomizev1.KustomizationKind,
Kinds: []*pb.GroupVersionKind{{Group: "apps", Version: "v1", Kind: "Deployment"}},
ClusterName: clustersmngr.DefaultCluster,
})
Expand Down
15 changes: 8 additions & 7 deletions core/server/objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
. "github.com/onsi/gomega"
"github.com/weaveworks/weave-gitops/core/server/types"
pb "github.com/weaveworks/weave-gitops/pkg/api/core"
Expand Down Expand Up @@ -42,7 +43,7 @@ func TestGetObject(t *testing.T) {
},
Spec: kustomizev1.KustomizationSpec{
SourceRef: kustomizev1.CrossNamespaceSourceReference{
Kind: "GitRepository",
Kind: sourcev1.GitRepositoryKind,
},
},
}
Expand Down Expand Up @@ -361,7 +362,7 @@ func TestListObjectSingle(t *testing.T) {

res, err := c.ListObjects(ctx, &pb.ListObjectsRequest{
Namespace: ns.Name,
Kind: "Kustomization",
Kind: kustomizev1.KustomizationKind,
})
g.Expect(err).NotTo(HaveOccurred())
g.Expect(res.Errors).To(BeEmpty())
Expand Down Expand Up @@ -413,7 +414,7 @@ func TestListObjectMultiple(t *testing.T) {

res, err := c.ListObjects(ctx, &pb.ListObjectsRequest{
Namespace: ns.Name,
Kind: "HelmRelease",
Kind: helmv2.HelmReleaseKind,
})
g.Expect(err).NotTo(HaveOccurred())
g.Expect(res.Errors).To(BeEmpty())
Expand Down Expand Up @@ -454,7 +455,7 @@ func TestListObjectSingleWithClusterName(t *testing.T) {

res, err := c.ListObjects(ctx, &pb.ListObjectsRequest{
Namespace: ns.Name,
Kind: "Kustomization",
Kind: kustomizev1.KustomizationKind,
ClusterName: "Default",
})
g.Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -507,7 +508,7 @@ func TestListObjectMultipleWithClusterName(t *testing.T) {

res, err := c.ListObjects(ctx, &pb.ListObjectsRequest{
Namespace: ns.Name,
Kind: "HelmRelease",
Kind: helmv2.HelmReleaseKind,
ClusterName: "Default",
})
g.Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -564,7 +565,7 @@ func TestListObject_HelmReleaseWithInventory(t *testing.T) {

res, err := c.ListObjects(ctx, &pb.ListObjectsRequest{
Namespace: ns.Name,
Kind: "HelmRelease",
Kind: helmv2.HelmReleaseKind,
})

g.Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -610,7 +611,7 @@ func TestListObject_HelmReleaseCantGetSecret(t *testing.T) {

res, err := c.ListObjects(ctx, &pb.ListObjectsRequest{
Namespace: ns.Name,
Kind: "HelmRelease",
Kind: helmv2.HelmReleaseKind,
})
g.Expect(err).NotTo(HaveOccurred())
g.Expect(res.Errors).To(HaveLen(1))
Expand Down
2 changes: 1 addition & 1 deletion core/server/suspend.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (cs *coreServer) ToggleSuspendResource(ctx context.Context, msg *pb.ToggleS
return &pb.ToggleSuspendResourceResponse{}, respErrors.ErrorOrNil()
}

func getReconcilableObject(kind pb.Kind) (fluxsync.Reconcilable, error) {
func getReconcilableObject(kind string) (fluxsync.Reconcilable, error) {
_, s, err := fluxsync.ToReconcileable(kind)

return s, err
Expand Down
6 changes: 3 additions & 3 deletions core/server/suspend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestSuspend_Suspend(t *testing.T) {
g := NewGomegaWithT(t)
g.Expect(k.Create(ctx, tt.obj)).Should(Succeed())
object := &api.ClusteredObjRef{
Kind: tt.kind,
Kind: tt.kind.String(),
Name: tt.obj.GetName(),
Namespace: tt.obj.GetNamespace(),
ClusterName: "Default",
Expand Down Expand Up @@ -101,11 +101,11 @@ func TestSuspend_Suspend(t *testing.T) {
_, err = c.ToggleSuspendResource(ctx, &api.ToggleSuspendResourceRequest{

Objects: []*api.ClusteredObjRef{{
Kind: api.Kind_GitRepository,
Kind: sourcev1.GitRepositoryKind,
Name: "fakeName",
Namespace: "fakeNamespace",
ClusterName: "Default",
}, {Kind: api.Kind_GitRepository,
}, {Kind: sourcev1.GitRepositoryKind,
Name: "fakeName2",
Namespace: "fakeNamespace2",
ClusterName: "Default2"}},
Expand Down

0 comments on commit d233509

Please sign in to comment.