utils

package
v0.0.0-...-bd111a6 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2020 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KUBENAMESPACE the namespace that kabanero is running in
	KUBENAMESPACE = "KUBE_NAMESPACE"
	// DEFAULTNAMESPACE the default namespace name
	DEFAULTNAMESPACE = "kabanero"
)
View Source
const (
	V1                         = "v1"
	V1ALPHA1                   = "v1alpha1"
	KABANEROIO                 = "kabanero.io"
	KABANEROS                  = "kabaneros"
	ANNOTATIONS                = "annotations"
	DATA                       = "data"
	URL                        = "url"
	USERNAME                   = "username"
	PASSWORD                   = "password"
	SECRETS                    = "secrets"
	SPEC                       = "spec"
	COLLECTIONS                = "collections"
	REPOSITORIES               = "repositories"
	ACTIVATEDEFAULTCOLLECTIONS = "activateDefaultCollections"
	METADATA                   = "metadata"
)

Kubernetes and Kabanero yaml constants

View Source
const (
	TRIGGERS = "triggers"
	CHKSUM   = "sha256"
)

constants

Variables

This section is empty.

Functions

func DecompressGzipTar

func DecompressGzipTar(readCloser io.ReadCloser, dir string) error

DecompressGzipTar Decompresses and extracts a tar.gz file.

func DownloadFileFromGithub

func DownloadFileFromGithub(owner, repository, fileName, ref, githubURL, user, token string, isEnterprise bool) ([]byte, bool, error)

DownloadFileFromGithub Downloads a file and returns: bytes of the file, true if file exists, and any error

func DownloadTrigger

func DownloadTrigger(triggerURL, triggerChkSum, dir string, verifyChkSum bool) error

DownloadTrigger Download the trigger.tar.gz and unpack into the directory

triggerURL: URL that serves the trigger gzipped tar
triggerChkSum: the sha256 checksum of the trigger archive
dir: directory to unpack the trigger.tar.gz

func DownloadYAML

func DownloadYAML(kubeClient *kubernetes.Clientset, header map[string][]string, bodyMap map[string]interface{}, fileName string) (map[string]interface{}, bool, error)

DownloadYAML Downloads a YAML file from a git repository.

header: HTTP header from webhook
bodyMap: HTTP  message body from webhook

func GetGitHubSecret

func GetGitHubSecret(client *kubernetes.Clientset, namespace string, repoURL string) (string, string, error)

GetGitHubSecret Find the user/token for a GitHub API key. The format of the secret: apiVersion: v1 kind: Secret metadata:

name: gh-https-secret
annotations:
  tekton.dev/git-0: https://github.com

type: kubernetes.io/basic-auth stringData:

username: <username>
password: <token>

This will scan for a secret with either of the following annotations:

  • tekton.dev/git-*
  • kabanero.io/git-*

GetGitHubSecret will return the username and token of a secret whose annotation's value is a prefix match for repoURL. Note that a secret with the `kabanero.io/git-*` annotation is preferred over one with `tekton.dev/git-*`. Return: username, token, error

func GetKabaneroNamespace

func GetKabaneroNamespace() string

GetKabaneroNamespace Get namespace of where kabanero is installed

func GetTriggerFiles

func GetTriggerFiles(client rest.Interface, url *url.URL, skipChkSumVerify bool) (string, error)

GetTriggerFiles returns the directory containing the retrieved trigger files.

func GetTriggerInfo

func GetTriggerInfo(client rest.Interface, namespace string) (*url.URL, string, error)

GetTriggerInfo Get the URL to trigger gzipped tar and its sha256 checksum.

func MergePathWithErrorCheck

func MergePathWithErrorCheck(dir string, toMerge string) (string, error)

MergePathWithErrorCheck Merge a directory path with a relative path. Return error if the rectory not a prefix of the merged path after the merge

func NewDynamicClient

func NewDynamicClient(kubeConfig *rest.Config) (dynamic.Interface, error)

NewDynamicClient Creates a new dynamic client

func NewKabConfig

func NewKabConfig(masterURL, kubeconfigPath string) (*rest.Config, error)

NewKabConfig Creates a new kabanero client config

func NewKubeClient

func NewKubeClient(kubeConfig *rest.Config) (*kubernetes.Clientset, error)

NewKubeClient Creates a new kube client

func NewKubeConfig

func NewKubeConfig(masterURL, kubeconfigPath string) (*rest.Config, error)

NewKubeConfig Creates a new kube config

func ReadFile

func ReadFile(fileName string) ([]byte, error)

ReadFile Reads a file and returns the bytes.

func ReadHTTPURL

func ReadHTTPURL(url string) ([]byte, error)

ReadHTTPURL Read remote file from URL and return bytes

func ReadJSON

func ReadJSON(fileName string) (*unstructured.Unstructured, error)

ReadJSON reads a JSON file and returns it as an unstructured.Unstructured object.

func ToDomainName

func ToDomainName(name string) string

ToDomainName Convert a name to domain name format. The name must:

  • Start with [a-z0-9]. If not, "0" is prepended.
  • lower case. If not, lower case is used.
  • contain only '.', '-', and [a-z0-9]. If not, "." is used insteaad.
  • end with alpha numeric characters. Otherwise, '0' is appended
  • can't have consecutive '.'. Consecutive ".." is substituted with ".".

Returns the empty string if the name is empty after conversion

func ToLabel

func ToLabel(input string) string

ToLabel Convert a string to Kubernetes label format.

func ToLabelName

func ToLabelName(name string) string

ToLabelName Convert the name part of a label. The name must:

  • Start with [a-z0-9A-Z]. If not, "0" is prepended.
  • End with [a-z0-9A-Z]. If not, "0" is appended
  • Intermediate characters can only be: [a-z0-9A-Z] or '_', '-', and '.' If not, '.' is used.
  • be maximum maxLabelLength characters long

func YAMLToMap

func YAMLToMap(bytes []byte) (map[string]interface{}, error)

YAMLToMap Converts a YAML byte array to a map.

Types

This section is empty.

Jump to

Keyboard shortcuts

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