Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit OSS vCluster that were imported into pro vClusters. #1865

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions cmd/vclusterctl/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (cmd *ListCmd) Run(cobraCmd *cobra.Command, _ []string) error {
}

var output []VCluster
output = append(output, ossToVClusters(vClusters, currentContext)...)
output = append(output, ossToVClusters(vClusters, proVClusters, currentContext)...)
output = append(output, proToVClusters(proVClusters, currentContext)...)

if cmd.output == "json" {
Expand All @@ -123,9 +123,22 @@ func (cmd *ListCmd) Run(cobraCmd *cobra.Command, _ []string) error {
return nil
}

func ossToVClusters(vClusters []find.VCluster, currentContext string) []VCluster {
func ossToVClusters(vClusters []find.VCluster, proVClusters []procli.VirtualClusterInstanceProject, currentContext string) []VCluster {
// Note all the imported pro vClusters, to omit their OSS counterparts from the listing
pvKeys := map[string]bool{}
for _, pvCluster := range proVClusters {
if pvCluster.VirtualCluster.Annotations["loft.sh/imported-by-agent"] == "true" {
clusterRef := pvCluster.VirtualCluster.Spec.ClusterRef
pvKeys[clusterRef.VirtualCluster+"/"+clusterRef.Namespace] = true
}
}

var output []VCluster
for _, vCluster := range vClusters {
if pvKeys[vCluster.Name+"/"+vCluster.Namespace] {
continue
}

vClusterOutput := VCluster{
Name: vCluster.Name,
Namespace: vCluster.Namespace,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ require (
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/evanphx/json-patch v5.8.1+incompatible
github.com/evanphx/json-patch v5.8.1+incompatible // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand Down
Loading