MCPcopy Create free account
hub / github.com/devspace-sh/devspace / GenericRequest

Method GenericRequest

pkg/devspace/kubectl/generic.go:31–121  ·  view source on GitHub ↗

GenericRequest makes a new request to the given server with the specified options

(ctx context.Context, options *GenericRequestOptions)

Source from the content-addressed store, hash-verified

29
30// GenericRequest makes a new request to the given server with the specified options
31func (client *client) GenericRequest(ctx context.Context, options *GenericRequestOptions) (string, error) {
32 // resolve Kind -> resource
33 if options.Kind != "" {
34 discoveryClient, err := discovery.NewDiscoveryClientForConfig(client.restConfig)
35 if err != nil {
36 return "", err
37 }
38
39 resources, err := discoveryClient.ServerResourcesForGroupVersion(options.APIVersion)
40 if err != nil {
41 return "", errors.Wrapf(err, "discover api version %s", options.APIVersion)
42 }
43
44 for _, resource := range resources.APIResources {
45 if resource.Kind == options.Kind {
46 options.Resource = resource.Name
47 if resource.Namespaced {
48 if options.Namespace == "" {
49 options.Namespace = client.Namespace()
50 }
51 } else {
52 options.Namespace = ""
53 }
54
55 break
56 }
57 }
58
59 if options.Resource == "" {
60 return "", fmt.Errorf("couldn't find resource for kind %s in api version %s", options.Kind, options.APIVersion)
61 }
62 }
63
64 // Create new client
65 var restClient restclient.Interface
66 if options.APIVersion != "" && options.APIVersion != "v1" {
67 splitted := strings.Split(options.APIVersion, "/")
68 if len(splitted) != 2 {
69 return "", errors.Errorf("Error parsing %s: expected version to be group/version", options.APIVersion)
70 }
71
72 config, err := client.ClientConfig().ClientConfig()
73 if err != nil {
74 return "", err
75 }
76
77 version := schema.GroupVersion{Group: splitted[0], Version: splitted[1]}
78 config.GroupVersion = &version
79 config.APIPath = "/apis"
80 config.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
81 if config.UserAgent == "" {
82 config.UserAgent = restclient.DefaultKubernetesUserAgent()
83 }
84
85 restClient, err = restclient.RESTClientFor(config)
86 if err != nil {
87 return "", err
88 }

Callers

nothing calls this directly

Calls 8

NamespaceMethod · 0.95
ClientConfigMethod · 0.95
KubeClientMethod · 0.95
ClientConfigMethod · 0.65
NamespaceMethod · 0.65
NameMethod · 0.65
ErrorfMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected