Skip to content

Commit ada6f25

Browse files
authored
Fixed to add annotations after calling loader.LoadManifests (#5777)
Signed-off-by: Yoshiki Fujikane <[email protected]>
1 parent e27f2d1 commit ada6f25

File tree

6 files changed

+46
-34
lines changed

6 files changed

+46
-34
lines changed

pkg/app/pipedv1/plugin/kubernetes/deployment/plugin.go

+19
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,25 @@ func (p *Plugin) loadManifests(ctx context.Context, deploy *sdk.Deployment, spec
114114
return nil, err
115115
}
116116

117+
// Add builtin labels and annotations for tracking application live state.
118+
for i := range manifests {
119+
manifests[i].AddLabels(map[string]string{
120+
provider.LabelManagedBy: provider.ManagedByPiped,
121+
provider.LabelPiped: deploy.PipedID,
122+
provider.LabelApplication: deploy.ApplicationID,
123+
provider.LabelCommitHash: deploymentSource.CommitHash,
124+
})
125+
126+
manifests[i].AddAnnotations(map[string]string{
127+
provider.LabelManagedBy: provider.ManagedByPiped,
128+
provider.LabelPiped: deploy.PipedID,
129+
provider.LabelApplication: deploy.ApplicationID,
130+
provider.LabelOriginalAPIVersion: manifests[i].APIVersion(),
131+
provider.LabelResourceKey: manifests[i].Key().String(),
132+
provider.LabelCommitHash: deploymentSource.CommitHash,
133+
})
134+
}
135+
117136
return manifests, nil
118137
}
119138

pkg/app/pipedv1/plugin/kubernetes/provider/loader.go

-17
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,6 @@ func (l *Loader) LoadManifests(ctx context.Context, input LoaderInput) (manifest
9191
if input.Namespace != "" {
9292
manifests[i].body.SetNamespace(input.Namespace)
9393
}
94-
95-
// Add builtin labels and annotations for tracking application live state.
96-
manifests[i].AddLabels(map[string]string{
97-
LabelManagedBy: ManagedByPiped,
98-
LabelPiped: input.PipedID,
99-
LabelApplication: input.AppID,
100-
LabelCommitHash: input.CommitHash,
101-
})
102-
103-
manifests[i].AddAnnotations(map[string]string{
104-
LabelManagedBy: ManagedByPiped,
105-
LabelPiped: input.PipedID,
106-
LabelApplication: input.AppID,
107-
LabelOriginalAPIVersion: manifests[i].body.GetAPIVersion(),
108-
LabelResourceKey: manifests[i].Key().String(),
109-
LabelCommitHash: input.CommitHash,
110-
})
11194
}
11295

11396
sortManifests(manifests)

pkg/app/pipedv1/plugin/kubernetes/provider/manifest.go

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ func (m Manifest) Kind() string {
6565
return m.body.GetKind()
6666
}
6767

68+
func (m Manifest) APIVersion() string {
69+
return m.body.GetAPIVersion()
70+
}
71+
6872
func (m Manifest) Name() string {
6973
return m.body.GetName()
7074
}

pkg/app/pipedv1/plugin/kubernetes_multicluster/deployment/plugin.go

+19
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,25 @@ func (p *Plugin) loadManifests(ctx context.Context, deploy *sdk.Deployment, spec
9898
return nil, err
9999
}
100100

101+
// Add builtin labels and annotations for tracking application live state.
102+
for i := range manifests {
103+
manifests[i].AddLabels(map[string]string{
104+
provider.LabelManagedBy: provider.ManagedByPiped,
105+
provider.LabelPiped: deploy.PipedID,
106+
provider.LabelApplication: deploy.ApplicationID,
107+
provider.LabelCommitHash: deploymentSource.CommitHash,
108+
})
109+
110+
manifests[i].AddAnnotations(map[string]string{
111+
provider.LabelManagedBy: provider.ManagedByPiped,
112+
provider.LabelPiped: deploy.PipedID,
113+
provider.LabelApplication: deploy.ApplicationID,
114+
provider.LabelOriginalAPIVersion: manifests[i].APIVersion(),
115+
provider.LabelResourceKey: manifests[i].Key().String(),
116+
provider.LabelCommitHash: deploymentSource.CommitHash,
117+
})
118+
}
119+
101120
return manifests, nil
102121
}
103122

pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/loader.go

-17
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,6 @@ func (l *Loader) LoadManifests(ctx context.Context, input LoaderInput) (manifest
9191
if input.Namespace != "" {
9292
manifests[i].body.SetNamespace(input.Namespace)
9393
}
94-
95-
// Add builtin labels and annotations for tracking application live state.
96-
manifests[i].AddLabels(map[string]string{
97-
LabelManagedBy: ManagedByPiped,
98-
LabelPiped: input.PipedID,
99-
LabelApplication: input.AppID,
100-
LabelCommitHash: input.CommitHash,
101-
})
102-
103-
manifests[i].AddAnnotations(map[string]string{
104-
LabelManagedBy: ManagedByPiped,
105-
LabelPiped: input.PipedID,
106-
LabelApplication: input.AppID,
107-
LabelOriginalAPIVersion: manifests[i].body.GetAPIVersion(),
108-
LabelResourceKey: manifests[i].Key().String(),
109-
LabelCommitHash: input.CommitHash,
110-
})
11194
}
11295

11396
sortManifests(manifests)

pkg/app/pipedv1/plugin/kubernetes_multicluster/provider/manifest.go

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ func (m Manifest) Kind() string {
6565
return m.body.GetKind()
6666
}
6767

68+
func (m Manifest) APIVersion() string {
69+
return m.body.GetAPIVersion()
70+
}
71+
6872
func (m Manifest) Name() string {
6973
return m.body.GetName()
7074
}

0 commit comments

Comments
 (0)