Skip to content

Commit

Permalink
Added restartpolicy and imagepullpolicy to kedge init
Browse files Browse the repository at this point in the history
resolves issue kedgeproject#601
  • Loading branch information
surajnarwade committed Feb 27, 2018
1 parent dbcc6fe commit 407ec48
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
22 changes: 14 additions & 8 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import (
)

var (
fileName, image, name string
controller string
ports []string
fileName, image, name string
controller string
imagepullpolicy, restartpolicy string
ports []string
)

/*
Expand All @@ -45,15 +46,18 @@ to spec in types.go.
*/

type Deployments struct {
Containers []Containers `json:"containers,omitempty"`
Containers []Containers `json:"containers,omitempty"`
RestartPolicy string `json:"restartPolicy,omitempty"`
}

type DeploymentConfigs struct {
Containers []Containers `json:"containers,omitempty"`
Containers []Containers `json:"containers,omitempty"`
RestartPolicy string `json:"restartPolicy,omitempty"`
}

type Containers struct {
Image string `json:"image,omitempty"`
Image string `json:"image,omitempty"`
ImagePullPolicy string `json:"imagePullPolicy,omitempty"`
}

type Service struct {
Expand Down Expand Up @@ -91,12 +95,12 @@ var initCmd = &cobra.Command{
case "deployment", "":
obj = App{
Name: name,
Deployments: []Deployments{{Containers: []Containers{{Image: image}}}},
Deployments: []Deployments{{Containers: []Containers{{Image: image, ImagePullPolicy: imagepullpolicy}}, RestartPolicy: restartpolicy}},
}
case "deploymentconfig":
obj = App{
Name: name,
DeploymentConfigs: []DeploymentConfigs{{Containers: []Containers{{Image: image}}}},
DeploymentConfigs: []DeploymentConfigs{{Containers: []Containers{{Image: image, ImagePullPolicy: imagepullpolicy}}, RestartPolicy: restartpolicy}},
}
default:
fmt.Println("'--controller' can only have values [Deployment, Job, DeploymentConfig].")
Expand Down Expand Up @@ -136,5 +140,7 @@ func init() {
initCmd.Flags().StringVarP(&image, "image", "i", "", "The image for the container to run")
initCmd.Flags().StringSliceVarP(&ports, "ports", "p", []string{}, "The ports that this container exposes")
initCmd.Flags().StringVarP(&controller, "controller", "c", "", "The type of controller this application is. Legal values [Deployment, Job, DeploymentConfig]. Default 'Deployment'.")
initCmd.Flags().StringVarP(&restartpolicy, "restart-policy", "r", "", "Type of restart policy. Legal values [Deployment, Job, DeploymentConfig]. ")
initCmd.Flags().StringVarP(&imagepullpolicy, "image-pull-policy", "", "", "xyz")
RootCmd.AddCommand(initCmd)
}
12 changes: 12 additions & 0 deletions tests/cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ func Test_init(t *testing.T) {
wantSuccess: true,
input: Fixtures + "init/kedge2.yml",
},
{
name: "kedge init with name & image & ports & restartPolicy",
command: []string{"init", "--name", svcname, "--image", image, "--ports", ports, "--restart-policy", "Always"},
wantSuccess: true,
input: Fixtures + "init/kedge3.yml",
},
{
name: "kedge init with name & image & ports & restartPolicy & imagePullPolicy",
command: []string{"init", "--name", svcname, "--image", image, "--ports", ports, "--restart-policy", "Always", "--image-pull-policy", "Always"},
wantSuccess: true,
input: Fixtures + "init/kedge4.yml",
},
}

for _, tt := range testCases {
Expand Down
8 changes: 8 additions & 0 deletions tests/cmd/fixtures/init/kedge3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
deployments:
- containers:
- image: centos/httpd
restartPolicy: Always
name: httpd
services:
- portMappings:
- "80"
9 changes: 9 additions & 0 deletions tests/cmd/fixtures/init/kedge4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
deployments:
- containers:
- image: centos/httpd
imagePullPolicy: Always
restartPolicy: Always
name: httpd
services:
- portMappings:
- "80"

0 comments on commit 407ec48

Please sign in to comment.