-
Notifications
You must be signed in to change notification settings - Fork 208
Add ArtifactVersion to KubernetesApp Deployment #3340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pipecd-bot
merged 12 commits into
pipe-cd:master
from
ffjlabo:add_artifact_versions_to_deployment
Mar 4, 2022
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
960fb73
Add ArtifactVersion to KubernetesApp Deployment
ffjlabo 5a48e20
Remove duplicate images on multiple manifests
ffjlabo f42f70c
Use ArtifactVersion_UNKNOWN when to unable to determine versions
ffjlabo 99b5c35
Fix comment
ffjlabo d276e45
Move ArtifactVersion to common.proto
ffjlabo 08317b9
Small fix
ffjlabo acbc946
Use strruct{}{} to have smaller size
ffjlabo 569159b
Add comment
ffjlabo 0930876
Return empty list when image couldn't find
ffjlabo 3275aa5
Fix proto field number
ffjlabo f969aa8
Move initialization versions slice
ffjlabo c23e18a
Fix comment
ffjlabo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -97,6 +97,18 @@ func (p *Planner) Plan(ctx context.Context, in planner.Input) (out planner.Outpu | |||||
| out.Version = version | ||||||
| } | ||||||
|
|
||||||
| if versions, e := determineVersions(newManifests); e != nil || len(versions) == 0 { | ||||||
| in.Logger.Error("unable to determine versions", zap.Error(e)) | ||||||
| out.Versions = []*model.ArtifactVersion{ | ||||||
| { | ||||||
| Kind: model.ArtifactVersion_UNKNOWN, | ||||||
| Version: versionUnknown, | ||||||
| }, | ||||||
| } | ||||||
| } else { | ||||||
| out.Versions = versions | ||||||
| } | ||||||
|
|
||||||
| autoRollback := *cfg.Input.AutoRollback | ||||||
|
|
||||||
| // In case the strategy has been decided by trigger. | ||||||
|
|
@@ -480,3 +492,42 @@ func determineVersion(manifests []provider.Manifest) (string, error) { | |||||
|
|
||||||
| return b.String(), nil | ||||||
| } | ||||||
|
|
||||||
| // determineVersions decides artifact versions of an application. | ||||||
| // It finds all container images that are being specified in the workload manifests then returns their names, version numbers, and urls. | ||||||
| func determineVersions(manifests []provider.Manifest) ([]*model.ArtifactVersion, error) { | ||||||
| imageMap := map[string]struct{}{} | ||||||
| for _, m := range manifests { | ||||||
| // TODO: Determine container image version from other workload kinds such as StatefulSet, Pod, Daemon, CronJob... | ||||||
| if !m.Key.IsDeployment() { | ||||||
| continue | ||||||
| } | ||||||
| data, err := m.MarshalJSON() | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
| var d resource.Deployment | ||||||
| if err := json.Unmarshal(data, &d); err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
|
|
||||||
| containers := d.Spec.Template.Spec.Containers | ||||||
| // remove duplicate images on multiple manifests | ||||||
|
||||||
| // remove duplicate images on multiple manifests | |
| // Remove duplicate images on multiple manifests. |
As our convention, comments start with a capital character and finish with a dot.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
pkg/app/piped/planner/kubernetes/testdata/version_multi_workloads_same_image.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: simple | ||
| labels: | ||
| app: simple | ||
| pipecd.dev/managed-by: piped | ||
| spec: | ||
| replicas: 2 | ||
| selector: | ||
| matchLabels: | ||
| app: simple | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: simple | ||
| spec: | ||
| containers: | ||
| - name: helloworld | ||
| image: gcr.io/pipecd/helloworld:v1.0.0 | ||
| args: | ||
| - hello | ||
| - hi | ||
| ports: | ||
| - containerPort: 9085 | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: my-service | ||
| spec: | ||
| selector: | ||
| app: MyApp | ||
| ports: | ||
| - protocol: TCP | ||
| port: 80 | ||
| targetPort: 9376 | ||
| --- | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: my-service | ||
| labels: | ||
| pipecd.dev/managed-by: piped | ||
| app: simple | ||
| spec: | ||
| replicas: 2 | ||
| selector: | ||
| matchLabels: | ||
| app: simple | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: simple | ||
| spec: | ||
| containers: | ||
| - name: helloworld | ||
| image: gcr.io/pipecd/helloworld:v1.0.0 | ||
| args: | ||
| - hi | ||
| - hello | ||
| ports: | ||
| - containerPort: 9085 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.