Skip to content

Commit a8df896

Browse files
committed
EPMDEDP-16587: feat: populate image digest in APPLICATIONS_PAYLOAD
Extend CodebaseTag with an optional Digest field so CDStageDeploy carries the image SHA256 digest from CBIS through the auto-deploy flow. The autodeploy strategy manager now includes imageDigest in the APPLICATIONS_PAYLOAD JSON. For the Auto (latest) strategy, digest is read directly from the CBIS latest tag. For the AutoStable strategy, the current triggered app gets digest from CDStageDeploy, stable apps get digest backfilled from CBIS during the InputDockerStreams iteration, and remaining apps use the latest tag digest. When digest is unavailable (pre-upgrade CBIS or old CDStageDeploy), the field is omitted via omitempty for full backward compatibility. Relates-to: EPMDEDP-16587 Signed-off-by: Sergiy Kulanov <sergiy_kulanov@epam.com>
1 parent c4b91b2 commit a8df896

7 files changed

Lines changed: 763 additions & 25 deletions

File tree

api/v1/cdstagedeploy_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type CDStageDeploySpec struct {
3939
type CodebaseTag struct {
4040
Codebase string `json:"codebase"`
4141
Tag string `json:"tag"`
42+
Digest string `json:"digest,omitempty"`
4243
}
4344

4445
// CDStageDeployStatus defines the observed state of CDStageDeploy.

config/crd/bases/v2.edp.epam.com_cdstagedeployments.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ spec:
6969
properties:
7070
codebase:
7171
type: string
72+
digest:
73+
type: string
7274
tag:
7375
type: string
7476
required:
@@ -83,6 +85,8 @@ spec:
8385
properties:
8486
codebase:
8587
type: string
88+
digest:
89+
type: string
8690
tag:
8791
type: string
8892
required:

controllers/codebaseimagestream/chain/put_cd_stage_deploy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ func getCreateCommand(
211211
Tag: codebaseApi.CodebaseTag{
212212
Codebase: codebase,
213213
Tag: lastTag.Name,
214+
Digest: lastTag.Digest,
214215
},
215216
}, nil
216217
}

deploy-templates/crds/v2.edp.epam.com_cdstagedeployments.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ spec:
6969
properties:
7070
codebase:
7171
type: string
72+
digest:
73+
type: string
7274
tag:
7375
type: string
7476
required:
@@ -83,6 +85,8 @@ spec:
8385
properties:
8486
codebase:
8587
type: string
88+
digest:
89+
type: string
8690
tag:
8791
type: string
8892
required:

docs/api.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ Specifies a latest available tag
172172
<br/>
173173
</td>
174174
<td>true</td>
175+
</tr><tr>
176+
<td><b>digest</b></td>
177+
<td>string</td>
178+
<td>
179+
<br/>
180+
</td>
181+
<td>false</td>
175182
</tr></tbody>
176183
</table>
177184

@@ -206,6 +213,13 @@ Specifies a latest available tag
206213
<br/>
207214
</td>
208215
<td>true</td>
216+
</tr><tr>
217+
<td><b>digest</b></td>
218+
<td>string</td>
219+
<td>
220+
<br/>
221+
</td>
222+
<td>false</td>
209223
</tr></tbody>
210224
</table>
211225

pkg/autodeploy/autodeploy.go

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ type StrategyManager struct {
3333
}
3434

3535
type ApplicationPayload struct {
36-
ImageTag string `json:"imageTag"`
36+
ImageTag string `json:"imageTag"`
37+
ImageDigest string `json:"imageDigest,omitempty"`
3738
}
3839

3940
func NewStrategyManager(k8sClient client.Client) *StrategyManager {
@@ -63,7 +64,8 @@ func (h *StrategyManager) GetAppPayloadForAllLatestStrategy(
6364
}
6465

6566
appPayload[codebase] = ApplicationPayload{
66-
ImageTag: tag,
67+
ImageTag: tag.Name,
68+
ImageDigest: tag.Digest,
6769
}
6870
}
6971

@@ -83,6 +85,7 @@ func (h *StrategyManager) GetAppPayloadForCurrentWithStableStrategy(
8385
) (json.RawMessage, error) {
8486
appPayload := make(map[string]ApplicationPayload, len(pipeline.Spec.InputDockerStreams))
8587

88+
// Stable apps: tag from annotation (digest will be backfilled in step 3).
8689
for _, app := range pipeline.Spec.Applications {
8790
t, ok := stage.GetAnnotations()[fmt.Sprintf("app.edp.epam.com/%s", app)]
8891
if ok {
@@ -92,10 +95,13 @@ func (h *StrategyManager) GetAppPayloadForCurrentWithStableStrategy(
9295
}
9396
}
9497

98+
// Current triggered app: tag and digest from CDStageDeploy.
9599
appPayload[current.Codebase] = ApplicationPayload{
96-
ImageTag: current.Tag,
100+
ImageTag: current.Tag,
101+
ImageDigest: current.Digest,
97102
}
98103

104+
// Remaining apps + backfill digest for stable apps from step 1.
99105
for _, stream := range pipeline.Spec.InputDockerStreams {
100106
imageStream, err := codebaseimagestream.GetCodebaseImageStreamByCodebaseBaseBranchName(
101107
ctx,
@@ -112,10 +118,15 @@ func (h *StrategyManager) GetAppPayloadForCurrentWithStableStrategy(
112118
return nil, err
113119
}
114120

115-
if _, ok := appPayload[codebase]; !ok {
121+
existing, exists := appPayload[codebase]
122+
if !exists {
116123
appPayload[codebase] = ApplicationPayload{
117-
ImageTag: tag,
124+
ImageTag: tag.Name,
125+
ImageDigest: tag.Digest,
118126
}
127+
} else if existing.ImageDigest == "" {
128+
existing.ImageDigest = findDigestByTagName(imageStream, existing.ImageTag)
129+
appPayload[codebase] = existing
119130
}
120131
}
121132

@@ -130,11 +141,27 @@ func (h *StrategyManager) GetAppPayloadForCurrentWithStableStrategy(
130141
func (*StrategyManager) getLatestTag(
131142
ctx context.Context,
132143
imageStream *codebaseApi.CodebaseImageStream,
133-
) (codebase, tag string, e error) {
144+
) (string, codebaseApi.Tag, error) {
134145
t, err := codebaseimagestream.GetLastTag(imageStream.Spec.Tags, ctrl.LoggerFrom(ctx))
135146
if err != nil {
136-
return "", "", ErrLasTagNotFound
147+
return "", codebaseApi.Tag{}, ErrLasTagNotFound
137148
}
138149

139-
return imageStream.Spec.Codebase, t.Name, nil
150+
return imageStream.Spec.Codebase, t, nil
151+
}
152+
153+
// findDigestByTagName looks up a digest for a given tag name in a CodebaseImageStream.
154+
// Returns an empty string if the CBIS is nil, the tag is not found, or the tag has no digest.
155+
func findDigestByTagName(cbis *codebaseApi.CodebaseImageStream, tagName string) string {
156+
if cbis == nil {
157+
return ""
158+
}
159+
160+
for _, tag := range cbis.Spec.Tags {
161+
if tag.Name == tagName {
162+
return tag.Digest
163+
}
164+
}
165+
166+
return ""
140167
}

0 commit comments

Comments
 (0)