-
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
Changes from 9 commits
960fb73
5a48e20
f42f70c
99b5c35
d276e45
08317b9
acbc946
569159b
0930876
3275aa5
f969aa8
c23e18a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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,43 @@ 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) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| versions := []*model.ArtifactVersion{} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move initialization versions slice to later to know its size.
| versions := []*model.ArtifactVersion{} | |
| 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 | |
| for _, c := range containers { | |
| imageMap[c.Image] = struct{}{} | |
| } | |
| } | |
| 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 | |
| for _, c := range containers { | |
| imageMap[c.Image] = struct{}{} | |
| } | |
| } | |
| versions := make([]*model.ArtifactVersion, 0, len(imageMap)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for suggestion!
| 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 |
Uh oh!
There was an error while loading. Please reload this page.