diff --git a/pkg/app/pipedv1/plugin/kubernetes_multicluster/livestate/plugin.go b/pkg/app/pipedv1/plugin/kubernetes_multicluster/livestate/plugin.go index ad07001e68..e0ce6b0c1a 100644 --- a/pkg/app/pipedv1/plugin/kubernetes_multicluster/livestate/plugin.go +++ b/pkg/app/pipedv1/plugin/kubernetes_multicluster/livestate/plugin.go @@ -320,14 +320,15 @@ type loader interface { LoadManifests(ctx context.Context, input provider.LoaderInput) ([]provider.Manifest, error) } -// TODO: share this implementation with the deployment plugin func (p Plugin) loadManifests(ctx context.Context, input *sdk.GetLivestateInput[kubeconfig.KubernetesApplicationSpec], spec *kubeconfig.KubernetesApplicationSpec, loader loader, logger *zap.Logger, multiTarget *kubeconfig.KubernetesMultiTarget) ([]provider.Manifest, error) { // override values if multiTarget has value. manifestPathes := spec.Input.Manifests + kustomizeDir := "" if multiTarget != nil { if len(multiTarget.Manifests) > 0 { manifestPathes = multiTarget.Manifests } + kustomizeDir = multiTarget.KustomizeDir } manifests, err := loader.LoadManifests(ctx, provider.LoaderInput{ @@ -340,6 +341,7 @@ func (p Plugin) loadManifests(ctx context.Context, input *sdk.GetLivestateInput[ Manifests: manifestPathes, Namespace: spec.Input.Namespace, KustomizeVersion: spec.Input.KustomizeVersion, + KustomizeDir: kustomizeDir, KustomizeOptions: spec.Input.KustomizeOptions, HelmVersion: spec.Input.HelmVersion, HelmChart: spec.Input.HelmChart, @@ -351,5 +353,23 @@ func (p Plugin) loadManifests(ctx context.Context, input *sdk.GetLivestateInput[ return nil, err } + // Add builtin labels and annotations for tracking application live state. + for i := range manifests { + manifests[i].AddLabels(map[string]string{ + provider.LabelManagedBy: provider.ManagedByPiped, + provider.LabelPiped: input.Request.PipedID, + provider.LabelApplication: input.Request.ApplicationID, + provider.LabelCommitHash: input.Request.DeploymentSource.CommitHash, + }) + manifests[i].AddAnnotations(map[string]string{ + provider.LabelManagedBy: provider.ManagedByPiped, + provider.LabelPiped: input.Request.PipedID, + provider.LabelApplication: input.Request.ApplicationID, + provider.LabelOriginalAPIVersion: manifests[i].APIVersion(), + provider.LabelResourceKey: manifests[i].Key().String(), + provider.LabelCommitHash: input.Request.DeploymentSource.CommitHash, + }) + } + return manifests, nil }