Documentation
¶
Index ¶
- Constants
- Variables
- func BuildApplicationLiveState(deploytarget string, manifests []Manifest, now time.Time) *model.ApplicationLiveState
- 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 Helm
- 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 (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) ConvertToStructuredObject(o interface{}) error
- func (m Manifest) GetAnnotations() map[string]string
- func (m Manifest) IsConfigMap() bool
- func (m Manifest) IsDeployment() bool
- func (m Manifest) IsManagedByPiped() bool
- func (m Manifest) IsSecret() 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) ToResourceState(deployTarget string) sdk.ResourceState
- 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 // 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" )
const ( KindDeployment = "Deployment" KindSecret = "Secret" KindConfigMap = "ConfigMap" DefaultNamespace = "default" )
Variables ¶
var (
ErrNotFound = errors.New("not found")
)
Functions ¶
func BuildApplicationLiveState ¶ added in v0.51.0
func BuildApplicationLiveState(deploytarget string, manifests []Manifest, now time.Time) *model.ApplicationLiveState
BuildApplicationLiveState builds the live state of the application from the given manifests.
func FindConfigsAndSecrets ¶ added in v0.51.0
func FindConfigsAndSecrets(manifests []Manifest) map[ResourceKey]Manifest
FindConfigsAndSecrets returns the manifests that are ConfigMap or Secret.
func FindContainerImages ¶ added in v0.51.0
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 ¶ added in v0.51.0
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 ¶ added in v0.51.0
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 ¶ added in v0.51.0
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 ¶ added in v0.51.0
HashManifests computes the hash of a list of manifests.
Types ¶
type Applier ¶ added in v0.51.0
type Applier struct {
// contains filtered or unexported fields
}
func NewApplier ¶ added in v0.51.0
func NewApplier(kubectl kubectl, input config.KubernetesDeploymentInput, cp config.KubernetesDeployTargetConfig, logger *zap.Logger) *Applier
func (*Applier) ApplyManifest ¶ added in v0.51.0
ApplyManifest does applying the given manifest.
func (*Applier) CreateManifest ¶ added in v0.51.0
CreateManifest uses kubectl to create the given manifests.
func (*Applier) Delete ¶ added in v0.51.0
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 ¶ added in v0.51.0
ForceReplaceManifest uses kubectl to forcefully replace the given manifests.
type Helm ¶
type Helm struct {
// contains filtered or unexported fields
}
func (*Helm) TemplateLocalChart ¶
type Kubectl ¶ added in v0.51.0
type Kubectl struct {
// contains filtered or unexported fields
}
Kubectl is a wrapper for kubectl command.
func NewKubectl ¶ added in v0.51.0
NewKubectl creates a new Kubectl instance.
func (*Kubectl) Apply ¶ added in v0.51.0
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 ¶ added in v0.51.0
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 ¶ added in v0.51.0
CreateNamespace runs kubectl create namespace with the given namespace.
func (*Kubectl) Delete ¶ added in v0.51.0
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 ¶ added in v0.51.0
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 ¶ added in v0.51.0
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 ¶ added in v0.51.0
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 ¶ added in v0.51.0
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 ¶ added in v0.51.0
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
TemplatingMethod TemplatingMethod
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 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) AddAnnotations ¶
func (Manifest) AddStringMapValues ¶ added in v0.51.0
AddStringMapValues adds or overrides the given key-values into the string map that can be found at the specified fields.
func (Manifest) ConvertToStructuredObject ¶ added in v0.51.0
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 first marshals the manifest to JSON and then unmarshals it into the provided object.
func (Manifest) GetAnnotations ¶ added in v0.51.0
func (Manifest) IsConfigMap ¶ added in v0.51.0
IsConfigMap returns true if the manifest is a ConfigMap. It checks the API group and the kind of the manifest.
func (Manifest) IsDeployment ¶ added in v0.51.0
IsDeployment returns true if the manifest is a Deployment. It checks the API group and the kind of the manifest.
func (Manifest) IsManagedByPiped ¶ added in v0.51.0
IsManagedByPiped returns true if the manifest is managed by Piped.
func (Manifest) IsSecret ¶ added in v0.51.0
IsSecret returns true if the manifest is a Secret. It checks the API group and the kind of the manifest.
func (Manifest) Key ¶
func (m Manifest) Key() ResourceKey
func (*Manifest) MarshalJSON ¶ added in v0.51.0
MarshalJSON implements the json.Marshaler interface. It marshals the underlying unstructured.Unstructured object into JSON bytes.
func (Manifest) ToResourceState ¶ added in v0.51.0
func (m Manifest) ToResourceState(deployTarget string) sdk.ResourceState
ToResourceState converts the manifest into a sdk.ResourceState.
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 ¶ added in v0.51.0
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 ¶ added in v0.51.0
WorkloadPair represents a pair of old and new manifests.
func FindSameManifests ¶ added in v0.51.0
func FindSameManifests(olds, news []Manifest) []WorkloadPair
FindSameManifests returns the pairs of old and new manifests that have the same key.