k8s_utility_client

package
v0.0.0-...-1373878 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Copyright <2022> Nik Ogura <nik.ogura@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

View Source
const IN_POD_NAMESPACE_FILE = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"

IN_POD_NAMESPACE_FILE If this file exists, odds are you're running in a k8s pod. From here we can determine both that we're in k8s, and what our current namespace is

Variables

This section is empty.

Functions

This section is empty.

Types

type K8sClients

type K8sClients struct {
	InCluster     bool
	ClientSet     *kubernetes.Clientset
	DynamicClient dynamic.Interface
	K8SConfig     *rest.Config
	Namespace     string
}

func NewK8sClients

func NewK8sClients() (clients *K8sClients, err error)

NewK8sClients Creates both standard k8s Clientsets and a Dynamic Clientset for Unstructured resources. Autodetcts whether it's running in a cluster, or outside. Looks for default config files in the usual places and automagically does the right thing.

func (*K8sClients) ApplyResources

func (k *K8sClients) ApplyResources(ctx context.Context, interfaces []dynamic.ResourceInterface, objects []*unstructured.Unstructured) (err error)

ApplyResources Takes a list of Unstructured interfaces and 'objects' and applies them to the cluster. ApplyResources will try to Get the resources first, and if they already exist, it will Update them.

func (*K8sClients) DeleteResources

func (k *K8sClients) DeleteResources(ctx context.Context, interfaces []dynamic.ResourceInterface, objects []*unstructured.Unstructured) (err error)

DeleteResources takes a list of Unstructured interfaces and 'objects' and performs a 'Foreground delete' upon them. See https://kubernetes.io/docs/concepts/architecture/garbage-collection/#foreground-deletion for more information about delete types.

func (*K8sClients) ResourcesAndObjectsFromBytes

func (k *K8sClients) ResourcesAndObjectsFromBytes(yamlBytes []byte) (interfaces []dynamic.ResourceInterface, objects []*unstructured.Unstructured, err error)

ResourcesAnd ObjectsFromYaml Reads k8s yaml files and converts them into Unstructured interfaces that can be applied to the cluster similar to `kubectl apply -f`

func (*K8sClients) ResourcesAndObjectsFromFile

func (k *K8sClients) ResourcesAndObjectsFromFile(fileName string) (interfaces []dynamic.ResourceInterface, objects []*unstructured.Unstructured, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL