-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2035 from FabianKramm/v0.20
[Backport v0.20] backport missing commits
- Loading branch information
Showing
11 changed files
with
274 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{{- if include "vcluster.rbac.createPlatformSecretRole" . }} | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: {{ include "vcluster.rbac.platformRoleName" . }} | ||
namespace: {{ include "vcluster.rbac.platformSecretNamespace" .}} | ||
rules: | ||
- apiGroups: [""] | ||
resources: ["secrets"] | ||
verbs: ["get"] | ||
resourceNames: | ||
- {{ include "vcluster.rbac.platformSecretName" . }} | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: {{ include "vcluster.rbac.platformRoleBindingName" . }} | ||
namespace: {{ include "vcluster.rbac.platformSecretNamespace" .}} | ||
subjects: | ||
- kind: ServiceAccount | ||
{{- if .Values.controlPlane.advanced.serviceAccount.name }} | ||
name: {{ .Values.controlPlane.advanced.serviceAccount.name }} | ||
{{- else }} | ||
name: vc-{{ .Release.Name }} | ||
{{- end }} | ||
namespace: {{ include "vcluster.rbac.platformSecretNamespace" .}} | ||
roleRef: | ||
kind: Role | ||
name: {{ include "vcluster.rbac.platformRoleName" . }} | ||
apiGroup: rbac.authorization.k8s.io | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
suite: Platform Secret Role | ||
templates: | ||
- platform-rbac.yaml | ||
|
||
tests: | ||
- it: check explicitly disabled | ||
set: | ||
external: | ||
platform: | ||
apiKey: | ||
namespace: "some-other-namespace" | ||
createRBAC: false | ||
asserts: | ||
- hasDocuments: | ||
count: 0 | ||
|
||
- it: check disabled on empty namespace | ||
set: | ||
external: | ||
platform: | ||
apiKey: | ||
namespace: "" | ||
asserts: | ||
- hasDocuments: | ||
count: 0 | ||
|
||
- it: check disabled on implicit same namespace | ||
set: | ||
external: | ||
platform: | ||
apiKey: | ||
secretName: "some-other-secret" | ||
asserts: | ||
- hasDocuments: | ||
count: 0 | ||
|
||
- it: automatically create role for specific secret for reading & patching | ||
set: | ||
external: | ||
platform: | ||
apiKey: | ||
secretName: "my-secret-name" | ||
namespace: "some-other-namespace" | ||
asserts: | ||
- hasDocuments: | ||
count: 2 | ||
- documentIndex: 0 | ||
lengthEqual: | ||
path: rules | ||
count: 1 | ||
- documentIndex: 0 | ||
equal: | ||
path: metadata.name | ||
value: "vc-RELEASE-NAME-v-NAMESPACE-platform-role" | ||
- documentIndex: 1 | ||
equal: | ||
path: metadata.name | ||
value: "vc-RELEASE-NAME-v-NAMESPACE-platform-role-binding" | ||
- documentIndex: 0 | ||
contains: | ||
path: rules | ||
count: 1 | ||
content: | ||
apiGroups: [""] | ||
resources: ["secrets"] | ||
verbs: ["get"] | ||
resourceNames: ["my-secret-name"] | ||
- documentIndex: 1 | ||
contains: | ||
path: subjects | ||
count: 1 | ||
content: | ||
kind: ServiceAccount | ||
name: vc-RELEASE-NAME | ||
namespace: some-other-namespace | ||
|
||
- it: automatically create role for default secret for reading & patching | ||
set: | ||
external: | ||
platform: | ||
apiKey: | ||
namespace: "some-other-namespace" | ||
asserts: | ||
- hasDocuments: | ||
count: 2 | ||
- documentIndex: 0 | ||
lengthEqual: | ||
path: rules | ||
count: 1 | ||
- documentIndex: 0 | ||
equal: | ||
path: metadata.name | ||
value: "vc-RELEASE-NAME-v-NAMESPACE-platform-role" | ||
- documentIndex: 1 | ||
equal: | ||
path: metadata.name | ||
value: "vc-RELEASE-NAME-v-NAMESPACE-platform-role-binding" | ||
- documentIndex: 0 | ||
contains: | ||
path: rules | ||
count: 1 | ||
content: | ||
apiGroups: [""] | ||
resources: ["secrets"] | ||
verbs: ["get"] | ||
resourceNames: ["vcluster-platform-api-key"] | ||
- documentIndex: 1 | ||
contains: | ||
path: subjects | ||
count: 1 | ||
content: | ||
kind: ServiceAccount | ||
name: vc-RELEASE-NAME | ||
namespace: some-other-namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package list | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/loft-sh/api/v4/pkg/product" | ||
"github.com/loft-sh/log" | ||
"github.com/loft-sh/log/table" | ||
"github.com/loft-sh/vcluster/pkg/cli/flags" | ||
"github.com/loft-sh/vcluster/pkg/platform" | ||
"github.com/spf13/cobra" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// ProjectsCmd holds the login cmd flags | ||
type ProjectsCmd struct { | ||
*flags.GlobalFlags | ||
|
||
log log.Logger | ||
} | ||
|
||
// newProjectsCmd creates a new spaces command | ||
func newProjectsCmd(globalFlags *flags.GlobalFlags) *cobra.Command { | ||
cmd := &ProjectsCmd{ | ||
GlobalFlags: globalFlags, | ||
log: log.GetInstance(), | ||
} | ||
description := product.ReplaceWithHeader("list projects", ` | ||
List the vcluster platform projects you have access to | ||
Example: | ||
vcluster platform list projects | ||
######################################################## | ||
`) | ||
projectsCmd := &cobra.Command{ | ||
Use: "projects", | ||
Short: product.Replace("Lists the loft projects you have access to"), | ||
Long: description, | ||
Args: cobra.NoArgs, | ||
RunE: func(cobraCmd *cobra.Command, _ []string) error { | ||
return cmd.RunProjects(cobraCmd.Context()) | ||
}, | ||
} | ||
|
||
return projectsCmd | ||
} | ||
|
||
// RunProjects executes the functionality | ||
func (cmd *ProjectsCmd) RunProjects(ctx context.Context) error { | ||
platformClient, err := platform.InitClientFromConfig(ctx, cmd.LoadedConfig(cmd.log)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
managementClient, err := platformClient.Management() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
projectList, err := managementClient.Loft().ManagementV1().Projects().List(ctx, metav1.ListOptions{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
header := []string{ | ||
"Project", | ||
} | ||
projects := make([][]string, len(projectList.Items)) | ||
for i, project := range projectList.Items { | ||
projects[i] = []string{project.Name} | ||
} | ||
|
||
table.PrintTable(cmd.log, header, projects) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters