Skip to content

Commit

Permalink
Make automation details use getObject instead of dedicated endpoints
Browse files Browse the repository at this point in the history
This requires adding dedicated inventory handling for helm releases -
rather than redesigning the inventory handling, I added an inventory
field to the object envelope and only set it when the kind is
helmrelease. This isn't good, but also it works and maintains the old
behaviour.

There is one change in behaviour, which is that inventory read
failures from the inventory secret no longer causes the object to
disappear from lists or refuse to render details. It'll now show up,
you just won't see any of the objects it's created. This is required
for #2664 but as listObjects isn't used to list helmReleases yet, it
doesn't actually resolve it.
  • Loading branch information
Robin Sonefors committed Sep 20, 2022
1 parent 847778d commit 3bf9fe8
Show file tree
Hide file tree
Showing 27 changed files with 1,229 additions and 1,933 deletions.
39 changes: 0 additions & 39 deletions api/core/core.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ service Core {
};
}

/*
* GetKustomization gets data about a single Kustomization from a cluster.
*/
rpc GetKustomization(GetKustomizationRequest) returns (GetKustomizationResponse) {
option (google.api.http) = {
get : "/v1/kustomizations/{name}"
};
}

/*
* ListHelmReleases lists helm releases from a cluster.
*/
Expand All @@ -50,16 +41,6 @@ service Core {
}


/*
* GetHelmRelease gets data about a single HelmRelease from the cluster.
*/
rpc GetHelmRelease(GetHelmReleaseRequest) returns (GetHelmReleaseResponse) {
option (google.api.http) = {
get : "/v1/helmrelease/{name}"
};
}


/*
* GetObject gets data about a single primary object from a cluster.
*/
Expand Down Expand Up @@ -214,16 +195,6 @@ message ListHelmReleasesResponse {
repeated ListError errors = 2;
}

message GetHelmReleaseRequest {
string name = 1;
string namespace = 2;
string clusterName = 3;
}

message GetHelmReleaseResponse {
HelmRelease helmRelease = 1;
}

message ListFluxRuntimeObjectsRequest {
string namespace = 1;
string clusterName = 2;
Expand All @@ -243,16 +214,6 @@ message ListFluxCrdsResponse {
repeated ListError errors = 2;
}

message GetKustomizationRequest {
string name = 1;
string namespace = 2;
string clusterName = 3;
}

message GetKustomizationResponse {
Kustomization kustomization = 1;
}

message GetObjectRequest {
string name = 1;
string namespace = 2;
Expand Down
108 changes: 6 additions & 102 deletions api/core/core.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,49 +183,6 @@
]
}
},
"/v1/helmrelease/{name}": {
"get": {
"summary": "GetHelmRelease gets data about a single HelmRelease from the cluster.",
"operationId": "Core_GetHelmRelease",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/v1GetHelmReleaseResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "name",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "namespace",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "clusterName",
"in": "query",
"required": false,
"type": "string"
}
],
"tags": [
"Core"
]
}
},
"/v1/helmreleases": {
"get": {
"summary": "ListHelmReleases lists helm releases from a cluster.",
Expand Down Expand Up @@ -301,49 +258,6 @@
]
}
},
"/v1/kustomizations/{name}": {
"get": {
"summary": "GetKustomization gets data about a single Kustomization from a cluster.",
"operationId": "Core_GetKustomization",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/v1GetKustomizationResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "name",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "namespace",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "clusterName",
"in": "query",
"required": false,
"type": "string"
}
],
"tags": [
"Core"
]
}
},
"/v1/namespace/flux": {
"post": {
"summary": "GetFluxNamespace returns with a namespace with a specific label.",
Expand Down Expand Up @@ -852,22 +766,6 @@
}
}
},
"v1GetHelmReleaseResponse": {
"type": "object",
"properties": {
"helmRelease": {
"$ref": "#/definitions/v1HelmRelease"
}
}
},
"v1GetKustomizationResponse": {
"type": "object",
"properties": {
"kustomization": {
"$ref": "#/definitions/v1Kustomization"
}
}
},
"v1GetObjectResponse": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1308,6 +1206,12 @@
},
"uid": {
"type": "string"
},
"inventory": {
"type": "array",
"items": {
"$ref": "#/definitions/v1GroupVersionKind"
}
}
}
},
Expand Down
9 changes: 5 additions & 4 deletions api/core/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ message HelmRelease {
}

message Object {
string payload = 1;
string clusterName = 2;
string tenant = 3;
string uid = 4;
string payload = 1;
string clusterName = 2;
string tenant = 3;
string uid = 4;
repeated GroupVersionKind inventory = 5;
}

message Deployment {
Expand Down
35 changes: 0 additions & 35 deletions core/server/helm_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,41 +74,6 @@ func (cs *coreServer) ListHelmReleases(ctx context.Context, msg *pb.ListHelmRele
}, nil
}

func (cs *coreServer) GetHelmRelease(ctx context.Context, msg *pb.GetHelmReleaseRequest) (*pb.GetHelmReleaseResponse, error) {
clustersClient, err := cs.clustersManager.GetImpersonatedClientForCluster(ctx, auth.Principal(ctx), msg.ClusterName)
if err != nil {
return nil, fmt.Errorf("error getting impersonating client: %w", err)
}

apiVersion := helmv2.GroupVersion.String()
helmRelease := helmv2.HelmRelease{}
key := client.ObjectKey{
Name: msg.Name,
Namespace: msg.Namespace,
}

if err := clustersClient.Get(ctx, msg.ClusterName, key, &helmRelease); err != nil {
return nil, err
}

inventory, err := getHelmReleaseInventory(ctx, helmRelease, clustersClient, msg.ClusterName)
if err != nil {
return nil, err
}

clusterUserNamespaces := cs.clustersManager.GetUserNamespaces(auth.Principal(ctx))

tenant := GetTenant(helmRelease.Namespace, msg.ClusterName, clusterUserNamespaces)

res := types.HelmReleaseToProto(&helmRelease, msg.ClusterName, inventory, tenant)

res.ApiVersion = apiVersion

return &pb.GetHelmReleaseResponse{
HelmRelease: res,
}, err
}

func getHelmReleaseInventory(ctx context.Context, helmRelease helmv2.HelmRelease, c clustersmngr.Client, cluster string) ([]*pb.GroupVersionKind, error) {
storageNamespace := helmRelease.GetStorageNamespace()

Expand Down
Loading

0 comments on commit 3bf9fe8

Please sign in to comment.