1 /* 2 Copyright The Helm Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package kube 18 19 import ( 20 "io" 21 "time" 22 23 v1 "k8s.io/api/core/v1" 24 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 "k8s.io/apimachinery/pkg/runtime" 26 ) 27 28 // Interface represents a client capable of communicating with the Kubernetes API. 29 // 30 // A KubernetesClient must be concurrency safe. 31 type Interface interface { 32 // Create creates one or more resources. 33 Create(resources ResourceList) (*Result, error) 34 35 // Wait waits up to the given timeout for the specified resources to be ready. 36 Wait(resources ResourceList, timeout time.Duration) error 37 38 // WaitWithJobs wait up to the given timeout for the specified resources to be ready, including jobs. 39 WaitWithJobs(resources ResourceList, timeout time.Duration) error 40 41 // Delete destroys one or more resources. 42 Delete(resources ResourceList) (*Result, []error) 43 44 // WatchUntilReady watches the resources given and waits until it is ready. 45 // 46 // This method is mainly for hook implementations. It watches for a resource to 47 // hit a particular milestone. The milestone depends on the Kind. 48 // 49 // For Jobs, "ready" means the Job ran to completion (exited without error). 50 // For Pods, "ready" means the Pod phase is marked "succeeded". 51 // For all other kinds, it means the kind was created or modified without 52 // error. 53 WatchUntilReady(resources ResourceList, timeout time.Duration) error 54 55 // Update updates one or more resources or creates the resource 56 // if it doesn't exist. 57 Update(original, target ResourceList, force bool) (*Result, error) 58 59 // Build creates a resource list from a Reader. 60 // 61 // Reader must contain a YAML stream (one or more YAML documents separated 62 // by "\n---\n") 63 // 64 // Validates against OpenAPI schema if validate is true. 65 Build(reader io.Reader, validate bool) (ResourceList, error) 66 67 // WaitAndGetCompletedPodPhase waits up to a timeout until a pod enters a completed phase 68 // and returns said phase (PodSucceeded or PodFailed qualify). 69 WaitAndGetCompletedPodPhase(name string, timeout time.Duration) (v1.PodPhase, error) 70 71 // IsReachable checks whether the client is able to connect to the cluster. 72 IsReachable() error 73 } 74 75 // InterfaceExt is introduced to avoid breaking backwards compatibility for Interface implementers. 76 // 77 // TODO Helm 4: Remove InterfaceExt and integrate its method(s) into the Interface. 78 type InterfaceExt interface { 79 // WaitForDelete wait up to the given timeout for the specified resources to be deleted. 80 WaitForDelete(resources ResourceList, timeout time.Duration) error 81 } 82 83 // InterfaceDeletionPropagation is introduced to avoid breaking backwards compatibility for Interface implementers. 84 // 85 // TODO Helm 4: Remove InterfaceDeletionPropagation and integrate its method(s) into the Interface. 86 type InterfaceDeletionPropagation interface { 87 // Delete destroys one or more resources. The deletion propagation is handled as per the given deletion propagation value. 88 DeleteWithPropagationPolicy(resources ResourceList, policy metav1.DeletionPropagation) (*Result, []error) 89 } 90 91 // InterfaceResources is introduced to avoid breaking backwards compatibility for Interface implementers. 92 // 93 // TODO Helm 4: Remove InterfaceResources and integrate its method(s) into the Interface. 94 type InterfaceResources interface { 95 // Get details of deployed resources. 96 // The first argument is a list of resources to get. The second argument 97 // specifies if related pods should be fetched. For example, the pods being 98 // managed by a deployment. 99 Get(resources ResourceList, related bool) (map[string][]runtime.Object, error) 100 101 // BuildTable creates a resource list from a Reader. This differs from 102 // Interface.Build() in that a table kind is returned. A table is useful 103 // if you want to use a printer to display the information. 104 // 105 // Reader must contain a YAML stream (one or more YAML documents separated 106 // by "\n---\n") 107 // 108 // Validates against OpenAPI schema if validate is true. 109 // TODO Helm 4: Integrate into Build with an argument 110 BuildTable(reader io.Reader, validate bool) (ResourceList, error) 111 } 112 113 var _ Interface = (*Client)(nil) 114 var _ InterfaceExt = (*Client)(nil) 115 var _ InterfaceDeletionPropagation = (*Client)(nil) 116 var _ InterfaceResources = (*Client)(nil) 117