github.com/stefanmcshane/helm@v0.0.0-20221213002717-88a4a2c6e77d/pkg/kube/interface.go (about)

     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  )
    25  
    26  // Interface represents a client capable of communicating with the Kubernetes API.
    27  //
    28  // A KubernetesClient must be concurrency safe.
    29  type Interface interface {
    30  	// Create creates one or more resources.
    31  	Create(resources ResourceList) (*Result, error)
    32  
    33  	// Wait waits up to the given timeout for the specified resources to be ready.
    34  	Wait(resources ResourceList, timeout time.Duration) error
    35  
    36  	// WaitWithJobs wait up to the given timeout for the specified resources to be ready, including jobs.
    37  	WaitWithJobs(resources ResourceList, timeout time.Duration) error
    38  
    39  	// Delete destroys one or more resources.
    40  	Delete(resources ResourceList) (*Result, []error)
    41  
    42  	// WatchUntilReady watches the resources given and waits until it is ready.
    43  	//
    44  	// This method is mainly for hook implementations. It watches for a resource to
    45  	// hit a particular milestone. The milestone depends on the Kind.
    46  	//
    47  	// For Jobs, "ready" means the Job ran to completion (exited without error).
    48  	// For Pods, "ready" means the Pod phase is marked "succeeded".
    49  	// For all other kinds, it means the kind was created or modified without
    50  	// error.
    51  	WatchUntilReady(resources ResourceList, timeout time.Duration) error
    52  
    53  	// Update updates one or more resources or creates the resource
    54  	// if it doesn't exist.
    55  	Update(original, target ResourceList, force bool) (*Result, error)
    56  
    57  	// Build creates a resource list from a Reader.
    58  	//
    59  	// Reader must contain a YAML stream (one or more YAML documents separated
    60  	// by "\n---\n")
    61  	//
    62  	// Validates against OpenAPI schema if validate is true.
    63  	Build(reader io.Reader, validate bool) (ResourceList, error)
    64  
    65  	// WaitAndGetCompletedPodPhase waits up to a timeout until a pod enters a completed phase
    66  	// and returns said phase (PodSucceeded or PodFailed qualify).
    67  	WaitAndGetCompletedPodPhase(name string, timeout time.Duration) (v1.PodPhase, error)
    68  
    69  	// IsReachable checks whether the client is able to connect to the cluster.
    70  	IsReachable() error
    71  }
    72  
    73  // InterfaceExt is introduced to avoid breaking backwards compatibility for Interface implementers.
    74  //
    75  // TODO Helm 4: Remove InterfaceExt and integrate its method(s) into the Interface.
    76  type InterfaceExt interface {
    77  	// WaitForDelete wait up to the given timeout for the specified resources to be deleted.
    78  	WaitForDelete(resources ResourceList, timeout time.Duration) error
    79  }
    80  
    81  var _ Interface = (*Client)(nil)
    82  var _ InterfaceExt = (*Client)(nil)