k8devel

package module
v0.0.0-...-8d31a75 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

README

k8s-go-devel

A Easy to use Go Library for Kubernetes

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareFiles

func CompareFiles(fileone string, filetwo string) (bool, error)

CompareFiles will compare two files, byte by byte to see if they are equal

Args:

 fileone - first file to compare
 filetwo - second file to compare

Returns:
   bool and error

func CreateDeployment

func CreateDeployment(c *Client, d *Deployment) error

Create will create a deployment

Args:

  • Client struct from client module
  • Deployment from this module

Returns:

  • error

func CreateEndpoint

func CreateEndpoint(c *Client, e *Endpoint) error

Create will create an endpoint

Args:

  • Client struct from client module
  • Instance from endpoint module

Return:

  • error or nil

func CreateNamespace

func CreateNamespace(c *Client, namespace string) error

CreateNamespace will create a namespace

Args:

  • Pointer to a Client struct
  • namespace name

Returns:

error or nil

func CreatePod

func CreatePod(c *Client, p *Pod) error

CreatePod will create a POD

Args:

  • Client struct from client module
  • Instance struct from pod module

Return:

  • error or nil

func CreateService

func CreateService(c *Client, s *Service) error

CreateService creates a service using the values from the Service struct via the Client.Clientset

Args:

 Service - Service struct
 Client  - Client strucut

Returns:
   error or nil

func CreateTempFile

func CreateTempFile(dirname string, filename string) (*os.File, error)

CreateTempFile will create temporary file

Args:

 dirname - dir name
 filename - file name

Returns:
   filename as string or error

func DeleteDeployment

func DeleteDeployment(c *Client, deployment string, namespace string) error

DeleteDeployment will delete an deployment

Args:

  • Client struct from client module
  • deployment name
  • namespace

Return:

  • error or nil

func DeleteEndpoint

func DeleteEndpoint(c *Client, endpoint string, namespace string) error

DeleteEndpoint will delete an endpoint

Args:

  • Client struct from client module
  • endpoint name
  • namespace

Return:

  • error or nil

func DeleteNamespace

func DeleteNamespace(c *Client, namespace string) error

DeleteNamespace will delete a namespace

Args:

  • Pointer to a Client struct
  • namespace name

Returns:

error or nil

func DeleteService

func DeleteService(c *Client, service string, namespace string) error

Delete deletes a service

Args:

	Client - client struct from the client module
	service - Service Name
	namespace - Namespace

  Returns:
     error or nil

func DetectContainerPortProtocol

func DetectContainerPortProtocol(protocol string) (v1.Protocol, error)

DetectContainerPortProtocol is a helper for users use only TCP or UDP string instead of require them to manage k8s.io/api/core/v1. This will convert TCP or UDP to v1.ProtocolTCP or v1.ProtocolUDP

Args:

protocol - TCP or UDP as string

Returns:

v1.ProtocolUDP, v1.ProtocolTCP or error

func DiffCommand

func DiffCommand(fileone string, filetwo string) ([]byte, error)

DiffCommand will diff two files

Args:

 fileone
 filtwo

Returns:
   bytes from the file or error

func ExecCmdPod

func ExecCmdPod(c *Client,
	podName string,
	nameSpace string,
	cmd []string) (bytes.Buffer, bytes.Buffer, error)

ExecCmdPod executes a command inside a POD

Args:

     Client - struct from client module
	podName	- The pod name
	cmd - Array (string)

Returns:

stdout, stderr as bytes.Buffer or error

func ExecuteHTTPReqInsideContainer

func ExecuteHTTPReqInsideContainer(c *Client,
	container string,
	namespace string,
	URL string) (string, error)

ExecuteHTTPReqFromInsideContainer will execute http request to a specific address

Args:

     client struct
     container name
	namespace
	URL

Returns:

output as string or error

func ExistsDeployment

func ExistsDeployment(c *Client, deployment string, namespace string) (string, error)

Exists will check if the service exists or not

Args:

Pointer to a Client struct
Service Name
Namespace

Returns:

string (namespace name) OR error type

func ExistsEndpoint

func ExistsEndpoint(c *Client, e *Endpoint) (string, error)

ExistsEndpoint will check if the endpoint exists or not

Args:

  • Client struct from client module
  • Instance struct from this module

Returns:

bool OR error type

func ExistsNamespace

func ExistsNamespace(c *Client, namespace string) (string, error)

Exists will check if the namespace exists or not

Args:

  • Pointer to a Client struct
  • namespace name

Returns:

string (namespace name) OR error type

func ExistsPod

func ExistsPod(c *Client, podName string, namespace string) (string, error)

ExistsPod will check if the pod exists or not

Args:

  • Pointer to a Client struct

Returns:

string (namespace name) OR error type

func ExistsService

func ExistsService(c *Client, service string, namespace string) (string, error)

Exists will check if the service exists or not

Args:

  • Pointer to a Client struct

Returns:

string (namespace name) OR error type

func FindPodsWithNameContains

func FindPodsWithNameContains(c *Client,
	substring string,
	namespace string) ([]string, int)

FindPodsWithNameContains will find pods with substring provided

Args:

  • Client struct from client module
  • substring to be found
  • namespace

Return:

  • error or nil

func GenerateRandomString

func GenerateRandomString(numberOfChars int, modeString string) (string, error)

GenerateRandomString will generate a random string

Args:

	number of chars to be generated
	modeString lower or all

  Returns:
	random string

func GetIPFromPod

func GetIPFromPod(c *Client,
	podName string,
	nameSpace string) (string, error)

GetIPFromPod will return the pod IP address

Args:

  • Client struct from client module
  • pod name
  • namespace

Returns:

  • the IP as string or error

func GetIPFromService

func GetIPFromService(c *Client,
	svcName string,
	nameSpace string) (string, error)

GetIPFromService will return the pod IP address

Args:

  • Client struct from client module
  • pod name
  • namespace

Returns:

  • the IP as string or error

func IPTablesSaveNatTable

func IPTablesSaveNatTable(c *Client,
	i *IPTables,
	container string,
	namespace string) (*os.File, error)

SaveNatTable save the current state of NAT table from the container provider in the parameter

Args:

container name
namespace

Returns:

file object
filesystem which triggered this method

func ListAllEndpoints

func ListAllEndpoints(c *Client, e *Endpoint)

ListAllEndpoints will list ALL endpoints from a namespace

Args:

  • Client struct from client module
  • Instance from endpoint module

Return:

  • error or nil

func PatchEndpoint

func PatchEndpoint(c *Client, e *Endpoint) error

Patch will patch an endpoint object

Args:

  • Client struct from client module
  • Instance from endpoint module

Return:

  • error or nil

func SetLogrusLogging

func SetLogrusLogging()

SetLogrusLogging will set the log format for logrus

Args:

  • None

Returns:

  • None

func ShowEndpoint

func ShowEndpoint(c *Client, endpoint string, namespace string) error

ShowEndpoint will display a specific endpoint Args:

  • Client struct from client module
  • endpoint name

Types

type Client

type Client struct {
	Clientset                  *kubernetes.Clientset
	Restclientset              *kubernetes.Clientset
	Namespace                  string
	Restconfig                 *rest.Config
	Kubeconfig                 clientcmd.ClientConfig
	TimeoutTaksInSec           int
	NumberMaxOfAttemptsPerTask int
}

Client struct contains all info about client to connect into the cluster

func (*Client) Connect

func (client *Client) Connect() *Client

Connect will connect to specific Cluster read from kubeconfig

Args:

Returns:

  • Client struct

func (*Client) KubeClientFromConfig

func (client *Client) KubeClientFromConfig() (*Client, error)

KubeClientFromConfig will provide the REST interface to cluster

Args:

Returns:

  • Client struct or error

type Deployment

type Deployment struct {
	Name       string
	Namespace  string
	Replicas   int32
	LabelKey   string
	LabelValue string
	Pod        struct {
		Name                  string
		Image                 string
		ContainerPortName     string
		ContainerPortProtocol string // "TCP" or "UDP"
		ContainerPort         int32
	}
}

Deployment type refers to the Deployment object

type Endpoint

type Endpoint struct {
	Name         string
	IP           string
	LabelKey     string
	LabelValue   string
	Namespace    string
	EndpointPort struct {
		Name     string
		Port     int32
		Protocol string
	}
}

Endpoint type refers to the Endpoint object

type IPTables

type IPTables struct {
	ReadNatTable             []string
	ReadFilterTable          []string
	ReadNatTableKubeServices []string
}

IPTables type refers to the iptables object

func IPTablesLoadPreDefinedCommands

func IPTablesLoadPreDefinedCommands() IPTables

LoadPreDefinedIPTables loads several pre-defined iptables commands.

Args:

None

Returns:

Filled IPTablesIPTables struct with commands

type Pod

type Pod struct {
	Name        string
	Namespace   string
	Image       string
	Command     []string
	CommandArgs []string
}

Pod type refers to the Pod object

type Service

type Service struct {
	Name          string
	Namespace     string
	LabelKey      string
	LabelValue    string
	Port          int32
	SelectorKey   string
	SelectorValue string
	ClusterIP     string
}

Service type refers to the Service object

Jump to

Keyboard shortcuts

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