Documentation
¶
Index ¶
- Constants
- Variables
- func Diff(old, new Manifest, logger *zap.Logger, opts ...diff.Option) (*diff.Result, error)
- func FindConfigsAndSecrets(manifests []Manifest) map[ResourceKey]Manifest
- func FindContainerImages(m Manifest) []string
- func FindReferencingConfigMaps(m Manifest) []string
- func FindReferencingSecrets(m Manifest) []string
- func GetLiveResources(ctx context.Context, kubectl *Kubectl, kubeconfig string, appID string, ...) (namespaceScoped []Manifest, clusterScoped []Manifest, _ error)
- func HashManifests(manifests []Manifest) (string, error)
- type Applier
- func (a *Applier) ApplyManifest(ctx context.Context, manifest Manifest) error
- func (a *Applier) CreateManifest(ctx context.Context, manifest Manifest) error
- func (a *Applier) Delete(ctx context.Context, k ResourceKey) (err error)
- func (a *Applier) ForceReplaceManifest(ctx context.Context, manifest Manifest) error
- func (a *Applier) ReplaceManifest(ctx context.Context, manifest Manifest) error
- type DiffListChange
- type DiffListResult
- type DiffRenderOptions
- type Helm
- func (h *Helm) AddRepository(ctx context.Context, repo config.HelmChartRepository) error
- func (h *Helm) LoginToOCIRegistry(ctx context.Context, address, username, password string) error
- func (h *Helm) TemplateLocalChart(ctx context.Context, appName, appDir, namespace, chartPath string, ...) (string, error)
- func (h *Helm) TemplateRemoteChart(ctx context.Context, appName, appDir, namespace string, chart helmRemoteChart, ...) (string, error)
- func (h *Helm) UpdateRepositories(ctx context.Context) error
- type Kubectl
- func (c *Kubectl) Apply(ctx context.Context, kubeconfig, namespace string, manifest Manifest) (err error)
- func (c *Kubectl) Create(ctx context.Context, kubeconfig, namespace string, manifest Manifest) (err error)
- func (c *Kubectl) CreateNamespace(ctx context.Context, kubeconfig, namespace string) (err error)
- func (c *Kubectl) Delete(ctx context.Context, kubeconfig, namespace string, r ResourceKey) (err error)
- func (c *Kubectl) ForceReplace(ctx context.Context, kubeconfig, namespace string, manifest Manifest) (err error)
- func (c *Kubectl) Get(ctx context.Context, kubeconfig, namespace string, r ResourceKey) (m Manifest, err error)
- func (c *Kubectl) GetAll(ctx context.Context, kubeconfig, namespace string, selector ...string) (ms []Manifest, err error)
- func (c *Kubectl) GetAllClusterScoped(ctx context.Context, kubeconfig string, selector ...string) ([]Manifest, error)
- func (c *Kubectl) Replace(ctx context.Context, kubeconfig, namespace string, manifest Manifest) (err error)
- type Kustomize
- type Loader
- type LoaderInput
- type Manifest
- func DeepCopyManifests(manifests []Manifest) []Manifest
- func FromStructuredObject(o any) (Manifest, error)
- func FromUnstructured(u *unstructured.Unstructured) Manifest
- func LoadManifestsFromYAMLFile(path string) ([]Manifest, error)
- func LoadPlainYAMLManifests(dir string, names []string, configFilename string) ([]Manifest, error)
- func ParseManifests(data string) ([]Manifest, error)
- func (m Manifest) APIVersion() string
- func (m Manifest) AddAnnotations(annotations map[string]string)
- func (m Manifest) AddLabels(labels map[string]string)
- func (m Manifest) AddStringMapValues(values map[string]string, fields ...string) error
- func (m Manifest) ApplicationID() string
- func (m Manifest) ConvertToStructuredObject(o any) error
- func (m Manifest) DeepCopy() Manifest
- func (m Manifest) DeepCopyWithName(name string) Manifest
- func (m Manifest) GetAnnotations() map[string]string
- func (m Manifest) GroupVersionKind() schema.GroupVersionKind
- func (m Manifest) IsConfigMap() bool
- func (m Manifest) IsDeployment() bool
- func (m Manifest) IsManagedByPiped() bool
- func (m Manifest) IsSecret() bool
- func (m Manifest) IsService() bool
- func (m Manifest) IsWorkload() bool
- func (m Manifest) Key() ResourceKey
- func (m Manifest) Kind() string
- func (m *Manifest) MarshalJSON() ([]byte, error)
- func (m Manifest) Name() string
- func (m Manifest) NestedMap(fields ...string) (map[string]any, bool, error)
- func (m Manifest) NestedString(fields ...string) (string, bool, error)
- func (m Manifest) OwnerReferences() []types.UID
- func (m Manifest) ToResourceState(deployTarget string) sdk.ResourceState
- func (m Manifest) UID() types.UID
- func (m *Manifest) UnmarshalJSON(data []byte) error
- func (m *Manifest) YamlBytes() ([]byte, error)
- type ResourceKey
- type TemplatingMethod
- type ToolRegistry
- type WorkloadPair
Constants ¶
const ( // labels 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. LabelSyncReplace = "pipecd.dev/sync-by-replace" // Use replace instead of apply. LabelForceSyncReplace = "pipecd.dev/force-sync-by-replace" // Use replace --force instead of apply. LabelServerSideApply = "pipecd.dev/server-side-apply" // Use server side apply instead of client side apply. 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. // annotations AnnotationOrder = "pipecd.dev/order" // The order number of resource used to sort them before using. AnnotationConfigHash = "pipecd.dev/config-hash" // The hash value of all mouting config resources. // label/annotation values ManagedByPiped = "piped" UseReplaceEnabled = "enabled" UseServerSideApply = "true" IgnoreDriftDetectionTrue = "true" )
const ( // Service KindService = "Service" // Workload KindDeployment = "Deployment" KindReplicaSet = "ReplicaSet" KindDaemonSet = "DaemonSet" KindPod = "Pod" // ConfigMap and Secret KindSecret = "Secret" KindConfigMap = "ConfigMap" DefaultNamespace = "default" )
Variables ¶
var (
ErrNotFound = errors.New("not found")
)
Functions ¶
func FindConfigsAndSecrets ¶
func FindConfigsAndSecrets(manifests []Manifest) map[ResourceKey]Manifest
FindConfigsAndSecrets returns the manifests that are ConfigMap or Secret.
func FindContainerImages ¶
FindContainerImages finds all container images that are referenced by the given manifest.
It looks for container images in the following fields: - spec.template.spec.containers.image
TODO: we should consider other fields like spec.template.spec.initContainers.image, spec.jobTempate.spec.template.spec.containers.image
func FindReferencingConfigMaps ¶
FindReferencingConfigMaps finds all configmaps that are referenced by the given manifest.
It looks for configmaps in the following fields: - spec.template.spec.volumes.configMap.name - spec.template.spec.initContainers.env.valueFrom.configMapKeyRef.name - spec.template.spec.initContainers.envFrom.configMapRef.name - spec.template.spec.containers.env.valueFrom.configMapKeyRef.name - spec.template.spec.containers.envFrom.configMapRef.name
func FindReferencingSecrets ¶
FindReferencingSecrets finds all secrets that are referenced by the given manifest.
It looks for secrets in the following fields: - spec.template.spec.volumes.secret.secretName - spec.template.spec.initContainers.env.valueFrom.secretKeyRef.name - spec.template.spec.initContainers.envFrom.secretRef.name - spec.template.spec.containers.env.valueFrom.secretKeyRef.name - spec.template.spec.containers.envFrom.secretRef.name
func GetLiveResources ¶
func GetLiveResources(ctx context.Context, kubectl *Kubectl, kubeconfig string, appID string, selector ...string) (namespaceScoped []Manifest, clusterScoped []Manifest, _ error)
GetLiveResources returns all live resources that belong to the given application.
func HashManifests ¶
HashManifests computes the hash of a list of manifests.
Types ¶
type Applier ¶
type Applier struct {
// contains filtered or unexported fields
}
func NewApplier ¶
func NewApplier(kubectl kubectl, input config.KubernetesDeploymentInput, cp config.KubernetesDeployTargetConfig, logger *zap.Logger) *Applier
func (*Applier) ApplyManifest ¶
ApplyManifest does applying the given manifest.
func (*Applier) CreateManifest ¶
CreateManifest uses kubectl to create the given manifests.
func (*Applier) Delete ¶
func (a *Applier) Delete(ctx context.Context, k ResourceKey) (err error)
Delete deletes the given resource from Kubernetes cluster. If the resource key is different, this returns ErrNotFound.
func (*Applier) ForceReplaceManifest ¶
ForceReplaceManifest uses kubectl to forcefully replace the given manifests.
type DiffListResult ¶
type DiffListResult struct { Adds []Manifest Deletes []Manifest Changes []DiffListChange }
func (*DiffListResult) NoChanges ¶
func (r *DiffListResult) NoChanges() bool
func (*DiffListResult) Render ¶
func (r *DiffListResult) Render(opt DiffRenderOptions) string
func (*DiffListResult) TotalOutOfSync ¶
func (r *DiffListResult) TotalOutOfSync() int
type DiffRenderOptions ¶
type Helm ¶
type Helm struct {
// contains filtered or unexported fields
}
func (*Helm) AddRepository ¶
Add installs all specified Helm Chart repositories. https://helm.sh/docs/topics/chart_repository/ helm repo add fantastic-charts https://fantastic-charts.storage.googleapis.com helm repo add fantastic-charts https://fantastic-charts.storage.googleapis.com --username my-username --password my-password
func (*Helm) LoginToOCIRegistry ¶
func (*Helm) TemplateLocalChart ¶
func (*Helm) TemplateRemoteChart ¶
type Kubectl ¶
type Kubectl struct {
// contains filtered or unexported fields
}
Kubectl is a wrapper for kubectl command.
func (*Kubectl) Apply ¶
func (c *Kubectl) Apply(ctx context.Context, kubeconfig, namespace string, manifest Manifest) (err error)
Apply runs kubectl apply command with the given manifest.
func (*Kubectl) Create ¶
func (c *Kubectl) Create(ctx context.Context, kubeconfig, namespace string, manifest Manifest) (err error)
Create runs kubectl create command with the given manifest.
func (*Kubectl) CreateNamespace ¶
CreateNamespace runs kubectl create namespace with the given namespace.
func (*Kubectl) Delete ¶
func (c *Kubectl) Delete(ctx context.Context, kubeconfig, namespace string, r ResourceKey) (err error)
Delete runs kubectl delete command with the given resource key.
func (*Kubectl) ForceReplace ¶
func (c *Kubectl) ForceReplace(ctx context.Context, kubeconfig, namespace string, manifest Manifest) (err error)
ForceReplace runs kubectl replace --force command with the given manifest.
func (*Kubectl) Get ¶
func (c *Kubectl) Get(ctx context.Context, kubeconfig, namespace string, r ResourceKey) (m Manifest, err error)
Get runs kubectl get with the gibven resource key.
func (*Kubectl) GetAll ¶
func (c *Kubectl) GetAll(ctx context.Context, kubeconfig, namespace string, selector ...string) (ms []Manifest, err error)
GetAll retrieves all Kubernetes resources in the specified namespace and matching the given selector. It returns a list of manifests or an error if the retrieval or unmarshalling fails. If no resources are found, it returns nil without an error.
func (*Kubectl) GetAllClusterScoped ¶
func (c *Kubectl) GetAllClusterScoped(ctx context.Context, kubeconfig string, selector ...string) ([]Manifest, error)
GetAllClusterScoped retrieves all cluster-scoped resources from the Kubernetes cluster using the provided kubeconfig and optional selectors. It returns a slice of Manifests representing the resources or an error if the operation fails.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
func NewLoader ¶
func NewLoader(registry ToolRegistry) *Loader
func (*Loader) LoadManifests ¶
type LoaderInput ¶
type LoaderInput struct { // for annotations to manage the application live state. PipedID string CommitHash string AppID string // for templating manifests AppName string AppDir string ConfigFilename string Manifests []string Namespace string KustomizeVersion string KustomizeOptions map[string]string HelmVersion string HelmChart *config.InputHelmChart HelmOptions *config.InputHelmOptions Logger *zap.Logger }
type Manifest ¶
type Manifest struct {
// contains filtered or unexported fields
}
Manifest represents a Kubernetes resource manifest.
func DeepCopyManifests ¶
DeepCopyManifests returns a deep copy of the given manifests.
func FromStructuredObject ¶
FromStructuredObject creates a new Manifest from a structured Kubernetes object.
func FromUnstructured ¶
func FromUnstructured(u *unstructured.Unstructured) Manifest
FromUnstructured creates a new Manifest from a Kubernetes unstructured object.
func LoadManifestsFromYAMLFile ¶
LoadManifestsFromYAMLFile loads the manifests from the given file.
func LoadPlainYAMLManifests ¶
func ParseManifests ¶
ParseManifests parses the given data and returns a list of Manifest.
func (Manifest) APIVersion ¶
func (Manifest) AddAnnotations ¶
func (Manifest) AddStringMapValues ¶
AddStringMapValues adds or overrides the given key-values into the string map that can be found at the specified fields.
func (Manifest) ApplicationID ¶
ApplicationID returns the application ID of the resource.
func (Manifest) ConvertToStructuredObject ¶
ConvertToStructuredObject converts the manifest into a structured Kubernetes object. The provided interface should be a pointer to a concrete Kubernetes type (e.g. *v1.Pod). It uses the runtime.DefaultUnstructuredConverter to convert the manifest into the provided object.
func (Manifest) DeepCopyWithName ¶
DeepCopyWithName returns a deep copy of the manifest with the given name.
func (Manifest) GetAnnotations ¶
func (Manifest) GroupVersionKind ¶
func (m Manifest) GroupVersionKind() schema.GroupVersionKind
func (Manifest) IsConfigMap ¶
IsConfigMap returns true if the manifest is a ConfigMap. It checks the API group and the kind of the manifest.
func (Manifest) IsDeployment ¶
IsDeployment returns true if the manifest is a Deployment. It checks the API group and the kind of the manifest.
func (Manifest) IsManagedByPiped ¶
IsManagedByPiped returns true if the manifest is managed by Piped.
func (Manifest) IsSecret ¶
IsSecret returns true if the manifest is a Secret. It checks the API group and the kind of the manifest.
func (Manifest) IsService ¶
IsService returns true if the manifest is a Service. It checks the API group and the kind of the manifest.
func (Manifest) IsWorkload ¶
IsWorkload returns true if the manifest is a Deployment, StatefulSet, or DaemonSet. It checks the API group and the kind of the manifest.
func (Manifest) Key ¶
func (m Manifest) Key() ResourceKey
func (*Manifest) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. It marshals the underlying unstructured.Unstructured object into JSON bytes.
func (Manifest) NestedString ¶
func (Manifest) OwnerReferences ¶
OwnerReferences returns the owner references of the resource.
func (Manifest) ToResourceState ¶
func (m Manifest) ToResourceState(deployTarget string) sdk.ResourceState
ToResourceState converts the manifest into a sdk.ResourceState.
func (Manifest) UID ¶
UID returns the UID of the resource. This will be empty when this manifest is loaded form the manifest file. This will be non-empty when this manifest is loaded from the live state.
func (*Manifest) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type ResourceKey ¶
type ResourceKey struct {
// contains filtered or unexported fields
}
ResourceKey represents a unique key of a Kubernetes resource. We use GroupKind, namespace, and name to identify a resource.
func FindRemoveResources ¶
func FindRemoveResources(manifests, namespacedLiveResources, clusterScopedLiveResources []Manifest) []ResourceKey
FindRemoveResources identifies resources that are present in the live state but not in the desired manifests. It doesn't return the resources that are not managed by Piped.
func (ResourceKey) Kind ¶
func (k ResourceKey) Kind() string
func (ResourceKey) Name ¶
func (k ResourceKey) Name() string
func (ResourceKey) Namespace ¶
func (k ResourceKey) Namespace() string
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" )
type ToolRegistry ¶
type WorkloadPair ¶
WorkloadPair represents a pair of old and new manifests.
func FindSameManifests ¶
func FindSameManifests(olds, news []Manifest) []WorkloadPair
FindSameManifests returns the pairs of old and new manifests that have the same key.