Skip to content

Commit 3ed4320

Browse files
committed
Add documentation for Kubernetes resource retrieval functions
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
1 parent b849517 commit 3ed4320

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pkg/app/pipedv1/plugin/kubernetes/provider/kubectl.go

+9
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ func (c *Kubectl) Get(ctx context.Context, kubeconfig, namespace string, r Resou
233233
return ms[0], nil
234234
}
235235

236+
// getAPIResources retrieves the list of available API resources from the Kubernetes cluster.
237+
// It runs the `kubectl api-resources` command with the specified kubeconfig and returns the
238+
// names of the resources that support the "list", "get", and "delete" verbs.
236239
func (c *Kubectl) getAPIResources(ctx context.Context, kubeconfig string) ([]string, error) {
237240
args := []string{"api-resources", "--namespaced=false", "--verbs=list,get,delete", "--output=name"}
238241
if kubeconfig != "" {
@@ -254,6 +257,9 @@ func (c *Kubectl) getAPIResources(ctx context.Context, kubeconfig string) ([]str
254257
return resources, nil
255258
}
256259

260+
// GetAllClusterScoped retrieves all cluster-scoped resources from the Kubernetes cluster
261+
// using the provided kubeconfig and optional selectors. It returns a slice of Manifests
262+
// representing the resources or an error if the operation fails.
257263
func (c *Kubectl) GetAllClusterScoped(ctx context.Context, kubeconfig string, selector ...string) ([]Manifest, error) {
258264
resources, err := c.getAPIResources(ctx, kubeconfig)
259265
if err != nil {
@@ -289,6 +295,9 @@ func (c *Kubectl) GetAllClusterScoped(ctx context.Context, kubeconfig string, se
289295
return ms, nil
290296
}
291297

298+
// GetAll retrieves all Kubernetes resources in the specified namespace and matching the given selector.
299+
// It returns a list of manifests or an error if the retrieval or unmarshalling fails.
300+
// If no resources are found, it returns nil without an error.
292301
func (c *Kubectl) GetAll(ctx context.Context, kubeconfig, namespace string, selector ...string) (ms []Manifest, err error) {
293302
args := make([]string, 0, 7)
294303
args = append(args, "get", "all", "-o", "yaml", "--selector", strings.Join(selector, ","))

pkg/app/pipedv1/plugin/kubernetes/provider/resource.go

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func normalizeGroupKind(gk schema.GroupKind) schema.GroupKind {
9191
return gk
9292
}
9393

94+
// FindRemoveResources identifies resources that are present in the live state but not in the desired manifests.
9495
func FindRemoveResources(manifests, namespacedLiveResources, clusterScopedLiveResources []Manifest) []ResourceKey {
9596
var (
9697
removeKeys = make([]ResourceKey, 0, len(namespacedLiveResources)+len(clusterScopedLiveResources))

0 commit comments

Comments
 (0)