2019-05-15 15:31:47 -04:00
|
|
|
/*
|
|
|
|
|
Copyright The Helm Authors.
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package kube
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"io"
|
|
|
|
|
"time"
|
|
|
|
|
|
2022-01-07 08:37:19 -05:00
|
|
|
v1 "k8s.io/api/core/v1"
|
2022-10-27 09:55:53 -04:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2022-09-09 04:55:06 -04:00
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
2019-05-15 15:31:47 -04:00
|
|
|
)
|
|
|
|
|
|
2019-08-02 00:04:59 -04:00
|
|
|
// Interface represents a client capable of communicating with the Kubernetes API.
|
2019-05-15 15:31:47 -04:00
|
|
|
//
|
|
|
|
|
// A KubernetesClient must be concurrency safe.
|
|
|
|
|
type Interface interface {
|
2025-06-15 00:20:44 -04:00
|
|
|
// Get details of deployed resources.
|
|
|
|
|
// The first argument is a list of resources to get. The second argument
|
|
|
|
|
// specifies if related pods should be fetched. For example, the pods being
|
|
|
|
|
// managed by a deployment.
|
|
|
|
|
Get(resources ResourceList, related bool) (map[string][]runtime.Object, error)
|
|
|
|
|
|
2019-05-15 15:31:47 -04:00
|
|
|
// Create creates one or more resources.
|
2025-07-03 15:59:23 -04:00
|
|
|
Create(resources ResourceList, options ...ClientCreateOption) (*Result, error)
|
2019-05-15 15:31:47 -04:00
|
|
|
|
2025-10-09 13:24:49 -04:00
|
|
|
// Delete destroys one or more resources using the specified deletion propagation policy.
|
|
|
|
|
// The 'policy' parameter determines how child resources are handled during deletion.
|
2025-06-15 00:20:44 -04:00
|
|
|
Delete(resources ResourceList, policy metav1.DeletionPropagation) (*Result, []error)
|
2019-05-15 15:31:47 -04:00
|
|
|
|
2025-01-14 10:03:21 -05:00
|
|
|
// Update updates one or more resources or creates the resource
|
|
|
|
|
// if it doesn't exist.
|
2025-07-03 15:59:23 -04:00
|
|
|
Update(original, target ResourceList, options ...ClientUpdateOption) (*Result, error)
|
2025-01-14 10:03:21 -05:00
|
|
|
|
2021-07-06 12:41:55 -04:00
|
|
|
// Build creates a resource list from a Reader.
|
2019-05-15 15:31:47 -04:00
|
|
|
//
|
2021-07-06 12:41:55 -04:00
|
|
|
// Reader must contain a YAML stream (one or more YAML documents separated
|
2019-07-24 16:24:32 -04:00
|
|
|
// by "\n---\n")
|
2019-10-08 15:55:19 -04:00
|
|
|
//
|
|
|
|
|
// Validates against OpenAPI schema if validate is true.
|
|
|
|
|
Build(reader io.Reader, validate bool) (ResourceList, error)
|
2021-07-06 12:41:55 -04:00
|
|
|
// IsReachable checks whether the client is able to connect to the cluster.
|
2019-08-25 17:42:48 -04:00
|
|
|
IsReachable() error
|
2025-03-25 10:15:27 -04:00
|
|
|
|
2026-01-08 20:18:33 -05:00
|
|
|
// GetWaiter gets the Kube.Waiter.
|
2025-03-25 09:55:39 -04:00
|
|
|
GetWaiter(ws WaitStrategy) (Waiter, error)
|
2025-06-15 00:20:44 -04:00
|
|
|
|
2025-10-09 13:26:24 -04:00
|
|
|
// GetPodList lists all pods that match the specified listOptions
|
2025-06-15 00:20:44 -04:00
|
|
|
GetPodList(namespace string, listOptions metav1.ListOptions) (*v1.PodList, error)
|
|
|
|
|
|
2025-10-09 13:26:24 -04:00
|
|
|
// OutputContainerLogsForPodList outputs the logs for a pod list
|
2025-06-15 00:20:44 -04:00
|
|
|
OutputContainerLogsForPodList(podList *v1.PodList, namespace string, writerFunc func(namespace, pod, container string) io.Writer) error
|
|
|
|
|
|
|
|
|
|
// BuildTable creates a resource list from a Reader. This differs from
|
|
|
|
|
// Interface.Build() in that a table kind is returned. A table is useful
|
|
|
|
|
// if you want to use a printer to display the information.
|
|
|
|
|
//
|
|
|
|
|
// Reader must contain a YAML stream (one or more YAML documents separated
|
|
|
|
|
// by "\n---\n")
|
|
|
|
|
//
|
|
|
|
|
// Validates against OpenAPI schema if validate is true.
|
|
|
|
|
// TODO Helm 4: Integrate into Build with an argument
|
|
|
|
|
BuildTable(reader io.Reader, validate bool) (ResourceList, error)
|
2024-12-26 11:09:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Waiter defines methods related to waiting for resource states.
|
|
|
|
|
type Waiter interface {
|
|
|
|
|
// Wait waits up to the given timeout for the specified resources to be ready.
|
|
|
|
|
Wait(resources ResourceList, timeout time.Duration) error
|
|
|
|
|
|
|
|
|
|
// WaitWithJobs wait up to the given timeout for the specified resources to be ready, including jobs.
|
|
|
|
|
WaitWithJobs(resources ResourceList, timeout time.Duration) error
|
2019-05-15 15:31:47 -04:00
|
|
|
|
2021-08-26 17:26:29 -04:00
|
|
|
// WaitForDelete wait up to the given timeout for the specified resources to be deleted.
|
|
|
|
|
WaitForDelete(resources ResourceList, timeout time.Duration) error
|
2025-02-07 10:14:25 -05:00
|
|
|
|
|
|
|
|
// WatchUntilReady watches the resources given and waits until it is ready.
|
|
|
|
|
//
|
|
|
|
|
// This method is mainly for hook implementations. It watches for a resource to
|
|
|
|
|
// hit a particular milestone. The milestone depends on the Kind.
|
|
|
|
|
//
|
|
|
|
|
// For Jobs, "ready" means the Job ran to completion (exited without error).
|
|
|
|
|
// For Pods, "ready" means the Pod phase is marked "succeeded".
|
|
|
|
|
// For all other kinds, it means the kind was created or modified without
|
|
|
|
|
// error.
|
|
|
|
|
WatchUntilReady(resources ResourceList, timeout time.Duration) error
|
2021-08-26 17:26:29 -04:00
|
|
|
}
|
2026-01-08 20:18:33 -05:00
|
|
|
|
|
|
|
|
// InterfaceWaitOptions defines an interface that extends Interface with
|
|
|
|
|
// methods that accept wait options.
|
|
|
|
|
//
|
|
|
|
|
// TODO Helm 5: Remove InterfaceWaitOptions and integrate its method(s) into the Interface.
|
|
|
|
|
type InterfaceWaitOptions interface {
|
|
|
|
|
// GetWaiter gets the Kube.Waiter with options.
|
|
|
|
|
GetWaiterWithOptions(ws WaitStrategy, opts ...WaitOption) (Waiter, error)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var _ InterfaceWaitOptions = (*Client)(nil)
|