Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/v1/cdstagedeploy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type CDStageDeploySpec struct {
type CodebaseTag struct {
Codebase string `json:"codebase"`
Tag string `json:"tag"`
Digest string `json:"digest,omitempty"`
}

// CDStageDeployStatus defines the observed state of CDStageDeploy.
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/v2.edp.epam.com_cdstagedeployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ spec:
properties:
codebase:
type: string
digest:
type: string
tag:
type: string
required:
Expand All @@ -83,6 +85,8 @@ spec:
properties:
codebase:
type: string
digest:
type: string
tag:
type: string
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ func getCreateCommand(
Tag: codebaseApi.CodebaseTag{
Codebase: codebase,
Tag: lastTag.Name,
Digest: lastTag.Digest,
},
}, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ spec:
properties:
codebase:
type: string
digest:
type: string
tag:
type: string
required:
Expand All @@ -83,6 +85,8 @@ spec:
properties:
codebase:
type: string
digest:
type: string
tag:
type: string
required:
Expand Down
14 changes: 14 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ Specifies a latest available tag
<br/>
</td>
<td>true</td>
</tr><tr>
<td><b>digest</b></td>
<td>string</td>
<td>
<br/>
</td>
<td>false</td>
</tr></tbody>
</table>

Expand Down Expand Up @@ -206,6 +213,13 @@ Specifies a latest available tag
<br/>
</td>
<td>true</td>
</tr><tr>
<td><b>digest</b></td>
<td>string</td>
<td>
<br/>
</td>
<td>false</td>
</tr></tbody>
</table>

Expand Down
43 changes: 35 additions & 8 deletions pkg/autodeploy/autodeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ type StrategyManager struct {
}

type ApplicationPayload struct {
ImageTag string `json:"imageTag"`
ImageTag string `json:"imageTag"`
ImageDigest string `json:"imageDigest,omitempty"`
}

func NewStrategyManager(k8sClient client.Client) *StrategyManager {
Expand Down Expand Up @@ -63,7 +64,8 @@ func (h *StrategyManager) GetAppPayloadForAllLatestStrategy(
}

appPayload[codebase] = ApplicationPayload{
ImageTag: tag,
ImageTag: tag.Name,
ImageDigest: tag.Digest,
}
}

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

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

// Current triggered app: tag and digest from CDStageDeploy.
appPayload[current.Codebase] = ApplicationPayload{
ImageTag: current.Tag,
ImageTag: current.Tag,
ImageDigest: current.Digest,
}

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

if _, ok := appPayload[codebase]; !ok {
existing, exists := appPayload[codebase]
if !exists {
appPayload[codebase] = ApplicationPayload{
ImageTag: tag,
ImageTag: tag.Name,
ImageDigest: tag.Digest,
}
} else if existing.ImageDigest == "" {
existing.ImageDigest = findDigestByTagName(imageStream, existing.ImageTag)
appPayload[codebase] = existing
}
}

Expand All @@ -130,11 +141,27 @@ func (h *StrategyManager) GetAppPayloadForCurrentWithStableStrategy(
func (*StrategyManager) getLatestTag(
ctx context.Context,
imageStream *codebaseApi.CodebaseImageStream,
) (codebase, tag string, e error) {
) (string, codebaseApi.Tag, error) {
t, err := codebaseimagestream.GetLastTag(imageStream.Spec.Tags, ctrl.LoggerFrom(ctx))
if err != nil {
return "", "", ErrLasTagNotFound
return "", codebaseApi.Tag{}, ErrLasTagNotFound
}

return imageStream.Spec.Codebase, t.Name, nil
return imageStream.Spec.Codebase, t, nil
}

// findDigestByTagName looks up a digest for a given tag name in a CodebaseImageStream.
// Returns an empty string if the CBIS is nil, the tag is not found, or the tag has no digest.
func findDigestByTagName(cbis *codebaseApi.CodebaseImageStream, tagName string) string {
if cbis == nil {
return ""
}

for _, tag := range cbis.Spec.Tags {
if tag.Name == tagName {
return tag.Digest
}
}

return ""
}
Loading
Loading