Skip to content

Commit

Permalink
Specify the Kind explicitly in the API resource
Browse files Browse the repository at this point in the history
Specify the Kind explicitly in the API resource to avoid wrong Kind conversion

Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com>
  • Loading branch information
ywk253100 committed Jan 19, 2024
1 parent 33bc0f1 commit 427a254
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 1 addition & 4 deletions pkg/test/discovery_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ package test
import (
"strings"

"golang.org/x/text/cases"
"golang.org/x/text/language"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/discovery"
discoveryfake "k8s.io/client-go/discovery/fake"
Expand Down Expand Up @@ -76,7 +73,7 @@ func (c *DiscoveryClient) WithAPIResource(resource *APIResource) *DiscoveryClien
Namespaced: resource.Namespaced,
Group: resource.Group,
Version: resource.Version,
Kind: cases.Title(language.Und).String(strings.TrimSuffix(resource.Name, "s")),
Kind: resource.Kind,
Verbs: metav1.Verbs([]string{"list", "create", "get", "delete"}),
ShortNames: []string{resource.ShortName},
})
Expand Down
15 changes: 15 additions & 0 deletions pkg/test/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type APIResource struct {
Group string
Version string
Name string
Kind string
ShortName string
Namespaced bool
Items []metav1.Object
Expand Down Expand Up @@ -59,6 +60,7 @@ func PVCs(items ...metav1.Object) *APIResource {
Version: "v1",
Name: "persistentvolumeclaims",
ShortName: "pvc",
Kind: "PersistentVolumeClaim",
Namespaced: true,
Items: items,
}
Expand All @@ -70,6 +72,7 @@ func PVs(items ...metav1.Object) *APIResource {
Version: "v1",
Name: "persistentvolumes",
ShortName: "pv",
Kind: "PersistentVolume",
Namespaced: false,
Items: items,
}
Expand All @@ -81,6 +84,7 @@ func Secrets(items ...metav1.Object) *APIResource {
Version: "v1",
Name: "secrets",
ShortName: "secrets",
Kind: "Secret",
Namespaced: true,
Items: items,
}
Expand All @@ -92,6 +96,7 @@ func Deployments(items ...metav1.Object) *APIResource {
Version: "v1",
Name: "deployments",
ShortName: "deploy",
Kind: "Deployment",
Namespaced: true,
Items: items,
}
Expand All @@ -103,6 +108,7 @@ func ExtensionsDeployments(items ...metav1.Object) *APIResource {
Version: "v1",
Name: "deployments",
ShortName: "deploy",
Kind: "Deployment",
Namespaced: true,
Items: items,
}
Expand All @@ -115,6 +121,7 @@ func VeleroDeployments(items ...metav1.Object) *APIResource {
Version: "v1",
Name: "deployments",
ShortName: "deploy",
Kind: "Deployment",
Namespaced: true,
Items: items,
}
Expand All @@ -126,6 +133,7 @@ func Namespaces(items ...metav1.Object) *APIResource {
Version: "v1",
Name: "namespaces",
ShortName: "ns",
Kind: "Namespace",
Namespaced: false,
Items: items,
}
Expand All @@ -137,6 +145,7 @@ func ServiceAccounts(items ...metav1.Object) *APIResource {
Version: "v1",
Name: "serviceaccounts",
ShortName: "sa",
Kind: "ServiceAccount",
Namespaced: true,
Items: items,
}
Expand All @@ -148,6 +157,7 @@ func ConfigMaps(items ...metav1.Object) *APIResource {
Version: "v1",
Name: "configmaps",
ShortName: "cm",
Kind: "ConfigMap",
Namespaced: true,
Items: items,
}
Expand All @@ -159,6 +169,7 @@ func CRDs(items ...metav1.Object) *APIResource {
Version: "v1beta1",
Name: "customresourcedefinitions",
ShortName: "crd",
Kind: "CustomResourceDefinition",
Namespaced: false,
Items: items,
}
Expand All @@ -169,6 +180,7 @@ func VSLs(items ...metav1.Object) *APIResource {
Group: "velero.io",
Version: "v1",
Name: "volumesnapshotlocations",
Kind: "VolumeSnapshotLocation",
Namespaced: true,
Items: items,
}
Expand All @@ -179,6 +191,7 @@ func Backups(items ...metav1.Object) *APIResource {
Group: "velero.io",
Version: "v1",
Name: "backups",
Kind: "Backup",
Namespaced: true,
Items: items,
}
Expand All @@ -190,6 +203,7 @@ func Services(items ...metav1.Object) *APIResource {
Version: "v1",
Name: "services",
ShortName: "svc",
Kind: "Service",
Namespaced: true,
Items: items,
}
Expand All @@ -200,6 +214,7 @@ func DataUploads(items ...metav1.Object) *APIResource {
Group: "velero.io",
Version: "v2alpha1",
Name: "datauploads",
Kind: "DataUpload",
Namespaced: true,
Items: items,
}
Expand Down

0 comments on commit 427a254

Please sign in to comment.