kubernetes

package
v0.32.2 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LabelManagedBy            = "pipecd.dev/managed-by"             // Always be piped.
	LabelPiped                = "pipecd.dev/piped"                  // The id of piped handling this application.
	LabelApplication          = "pipecd.dev/application"            // The application this resource belongs to.
	LabelCommitHash           = "pipecd.dev/commit-hash"            // Hash value of the deployed commit.
	LabelResourceKey          = "pipecd.dev/resource-key"           // The resource key generated by apiVersion, namespace and name. e.g. apps/v1/Deployment/namespace/demo-app
	LabelOriginalAPIVersion   = "pipecd.dev/original-api-version"   // The api version defined in git configuration. e.g. apps/v1
	LabelIgnoreDriftDirection = "pipecd.dev/ignore-drift-detection" // Whether the drift detection should ignore this resource.
	LabelSyncReplace          = "pipecd.dev/sync-by-replace"        // Use replace instead of apply.
	AnnotationConfigHash      = "pipecd.dev/config-hash"            // The hash value of all mouting config resources.
	ManagedByPiped            = "piped"
	IgnoreDriftDetectionTrue  = "true"
	UseReplaceEnabled         = "enabled"
)
View Source
const (
	KindDeployment               = "Deployment"
	KindStatefulSet              = "StatefulSet"
	KindDaemonSet                = "DaemonSet"
	KindReplicaSet               = "ReplicaSet"
	KindPod                      = "Pod"
	KindJob                      = "Job"
	KindCronJob                  = "CronJob"
	KindConfigMap                = "ConfigMap"
	KindSecret                   = "Secret"
	KindPersistentVolume         = "PersistentVolume"
	KindPersistentVolumeClaim    = "PersistentVolumeClaim"
	KindService                  = "Service"
	KindIngress                  = "Ingress"
	KindServiceAccount           = "ServiceAccount"
	KindRole                     = "Role"
	KindRoleBinding              = "RoleBinding"
	KindClusterRole              = "ClusterRole"
	KindClusterRoleBinding       = "ClusterRoleBinding"
	KindNameSpace                = "NameSpace"
	KindPodDisruptionBudget      = "PodDisruptionBudget"
	KindCustomResourceDefinition = "CustomResourceDefinition"

	DefaultNamespace = "default"
)

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
)

Functions

func Diff

func Diff(old, new Manifest, logger *zap.Logger, opts ...diff.Option) (*diff.Result, error)

func FindReferencingConfigMapsInDeployment

func FindReferencingConfigMapsInDeployment(d *appsv1.Deployment) []string

func FindReferencingSecretsInDeployment

func FindReferencingSecretsInDeployment(d *appsv1.Deployment) []string

func HashManifests

func HashManifests(manifests []Manifest) (string, error)

HashManifests computes the hash of a list of manifests.

func IsKubernetesBuiltInResource

func IsKubernetesBuiltInResource(apiVersion string) bool

Types

type APIVersionKind

type APIVersionKind struct {
	APIVersion string
	Kind       string
}

type AppManifestsCache

type AppManifestsCache struct {
	AppID  string
	Cache  cache.Cache
	Logger *zap.Logger
}

func (AppManifestsCache) Get

func (c AppManifestsCache) Get(commit string) ([]Manifest, bool)

func (AppManifestsCache) Put

func (c AppManifestsCache) Put(commit string, manifests []Manifest)

type Applier

type Applier interface {
	// ApplyManifest does applying the given manifest.
	ApplyManifest(ctx context.Context, manifest Manifest) error
	// CreateManifest does creating resource from given manifest.
	CreateManifest(ctx context.Context, manifest Manifest) error
	// ReplaceManifest does replacing resource from given manifest.
	ReplaceManifest(ctx context.Context, manifest Manifest) error
	// Delete deletes the given resource from Kubernetes cluster.
	Delete(ctx context.Context, key ResourceKey) error
}

func NewApplier added in v0.27.0

type DiffListChange

type DiffListChange struct {
	Old  Manifest
	New  Manifest
	Diff *diff.Result
}

type DiffListResult

type DiffListResult struct {
	Adds    []Manifest
	Deletes []Manifest
	Changes []DiffListChange
}

func DiffList

func DiffList(olds, news []Manifest, logger *zap.Logger, opts ...diff.Option) (*DiffListResult, error)

func (*DiffListResult) NoChange

func (r *DiffListResult) NoChange() bool

func (*DiffListResult) Render

func (r *DiffListResult) Render(opt DiffRenderOptions) string

type DiffRenderOptions

type DiffRenderOptions struct {
	MaskSecret    bool
	MaskConfigMap bool
	// Maximum number of changed manifests should be shown.
	// Zero means rendering all.
	MaxChangedManifests int
	// If true, use "diff" command to render.
	UseDiffCommand bool
}

type Helm

type Helm struct {
	// contains filtered or unexported fields
}

func NewHelm

func NewHelm(version, path string, logger *zap.Logger) *Helm

func (*Helm) TemplateLocalChart

func (c *Helm) TemplateLocalChart(ctx context.Context, appName, appDir, namespace, chartPath string, opts *config.InputHelmOptions) (string, error)

func (*Helm) TemplateRemoteChart

func (c *Helm) TemplateRemoteChart(ctx context.Context, appName, appDir, namespace string, chart helmRemoteChart, opts *config.InputHelmOptions) (string, error)

func (*Helm) TemplateRemoteGitChart

func (c *Helm) TemplateRemoteGitChart(ctx context.Context, appName, appDir, namespace string, chart helmRemoteGitChart, gitClient gitClient, opts *config.InputHelmOptions) (string, error)

type Kubectl

type Kubectl struct {
	// contains filtered or unexported fields
}

func NewKubectl

func NewKubectl(version, path string) *Kubectl

func (*Kubectl) Apply

func (c *Kubectl) Apply(ctx context.Context, kubeconfig, namespace string, manifest Manifest) (err error)

func (*Kubectl) Create added in v0.25.1

func (c *Kubectl) Create(ctx context.Context, kubeconfig, namespace string, manifest Manifest) (err error)

func (*Kubectl) Delete

func (c *Kubectl) Delete(ctx context.Context, kubeconfig, namespace string, r ResourceKey) (err error)

func (*Kubectl) Get added in v0.31.0

func (c *Kubectl) Get(ctx context.Context, kubeconfig, namespace string, r ResourceKey) (m Manifest, err error)

func (*Kubectl) Replace added in v0.25.1

func (c *Kubectl) Replace(ctx context.Context, kubeconfig, namespace string, manifest Manifest) (err error)

type Kustomize

type Kustomize struct {
	// contains filtered or unexported fields
}

func NewKustomize

func NewKustomize(version, path string, logger *zap.Logger) *Kustomize

func (*Kustomize) Template

func (c *Kustomize) Template(ctx context.Context, appName, appDir string, opts map[string]string) (string, error)

type Loader added in v0.27.0

type Loader interface {
	// LoadManifests renders and loads all manifests for application.
	LoadManifests(ctx context.Context) ([]Manifest, error)
}

func NewLoader added in v0.27.0

func NewLoader(
	appName, appDir, repoDir, configFileName string,
	input config.KubernetesDeploymentInput,
	gc gitClient,
	logger *zap.Logger,
) Loader

type Manifest

type Manifest struct {
	Key ResourceKey
	// contains filtered or unexported fields
}

func LoadManifestsFromYAMLFile

func LoadManifestsFromYAMLFile(path string) ([]Manifest, error)

func LoadPlainYAMLManifests

func LoadPlainYAMLManifests(dir string, names []string, configFileName string) ([]Manifest, error)

func MakeManifest

func MakeManifest(key ResourceKey, u *unstructured.Unstructured) Manifest

func ParseFromStructuredObject

func ParseFromStructuredObject(s interface{}) (Manifest, error)

func ParseManifests

func ParseManifests(data string) ([]Manifest, error)

func (Manifest) AddAnnotations

func (m Manifest) AddAnnotations(annotations map[string]string)

func (Manifest) AddStringMapValues

func (m Manifest) AddStringMapValues(values map[string]string, fields ...string) error

AddStringMapValues adds or overrides the given key-values into the string map that can be found at the specified fields.

func (Manifest) ConvertToStructuredObject

func (m Manifest) ConvertToStructuredObject(o interface{}) error

func (Manifest) Duplicate

func (m Manifest) Duplicate(name string) Manifest

func (Manifest) GetAnnotations

func (m Manifest) GetAnnotations() map[string]string

func (Manifest) GetNestedMap

func (m Manifest) GetNestedMap(fields ...string) (map[string]interface{}, error)

func (Manifest) GetNestedStringMap

func (m Manifest) GetNestedStringMap(fields ...string) (map[string]string, error)

func (Manifest) GetSpec

func (m Manifest) GetSpec() (interface{}, error)

func (Manifest) MarshalJSON

func (m Manifest) MarshalJSON() ([]byte, error)

func (Manifest) SetStructuredSpec

func (m Manifest) SetStructuredSpec(spec interface{}) error

func (Manifest) YamlBytes

func (m Manifest) YamlBytes() ([]byte, error)

type ResourceKey

type ResourceKey struct {
	APIVersion string
	Kind       string
	Namespace  string
	Name       string
}

func DecodeResourceKey

func DecodeResourceKey(key string) (ResourceKey, error)

func MakeResourceKey

func MakeResourceKey(obj *unstructured.Unstructured) ResourceKey

func (ResourceKey) IsConfigMap

func (k ResourceKey) IsConfigMap() bool

func (ResourceKey) IsDeployment

func (k ResourceKey) IsDeployment() bool

func (ResourceKey) IsEqualWithIgnoringNamespace

func (k ResourceKey) IsEqualWithIgnoringNamespace(a ResourceKey) bool

IsEqualWithIgnoringNamespace checks whether the key is equal to the given key, but this ignores the comparation of the namesapce.

func (ResourceKey) IsLess

func (k ResourceKey) IsLess(a ResourceKey) bool

IsLess reports whether the key should sort before the given key.

func (ResourceKey) IsLessWithIgnoringNamespace

func (k ResourceKey) IsLessWithIgnoringNamespace(a ResourceKey) bool

IsLessWithIgnoringNamespace reports whether the key should sort before the given key, but this ignores the comparation of the namesapce.

func (ResourceKey) IsReplicaSet

func (k ResourceKey) IsReplicaSet() bool

func (ResourceKey) IsSecret

func (k ResourceKey) IsSecret() bool

func (ResourceKey) IsService

func (k ResourceKey) IsService() bool

func (ResourceKey) IsWorkload

func (k ResourceKey) IsWorkload() bool

func (ResourceKey) IsZero

func (k ResourceKey) IsZero() bool

func (ResourceKey) ReadableLogString

func (k ResourceKey) ReadableLogString() string

TODO: Ensure the ResourceKey's Namespace used for Kubernetes diff detection works with the current ResourceKey Namespace loading model

func (ResourceKey) ReadableString

func (k ResourceKey) ReadableString() string

func (ResourceKey) String

func (k ResourceKey) String() string

type TemplatingMethod

type TemplatingMethod string
const (
	TemplatingMethodHelm      TemplatingMethod = "helm"
	TemplatingMethodKustomize TemplatingMethod = "kustomize"
	TemplatingMethodNone      TemplatingMethod = "none"
)

Directories

Path Synopsis
Package kubernetestest is a generated GoMock package.
Package kubernetestest is a generated GoMock package.

Jump to

Keyboard shortcuts

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