Skip to content

Commit

Permalink
Add baseImageOverride to backplane-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorakemp committed Sep 28, 2023
1 parent 9d5f461 commit 1deb1f7
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 50 deletions.
4 changes: 1 addition & 3 deletions cmd/ocm-backplane/managedJob/createManagedJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ func createJob(client BackplaneApi.ClientInterface) (*BackplaneApi.Job, error) {
// create job request
createJob := BackplaneApi.CreateJobJSONRequestBody{
CanonicalName: &options.canonicalName,
Parameters: &BackplaneApi.CreateJob_Parameters{
AdditionalProperties: jobParams,
},
Parameters: &jobParams,
}

// call create end point
Expand Down
22 changes: 20 additions & 2 deletions cmd/ocm-backplane/testJob/createTestJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Example usage:
"params",
"p",
[]string{},
"Params to be passed to managedjob execution in json format. For e.g. -p 'VAR1=VAL1' -p VAR2=VAL2 ")
"Params to be passed to managedjob execution in json format. Example: -p 'VAR1=VAL1' -p VAR2=VAL2 ")

cmd.Flags().StringP(
"library-file-path",
Expand All @@ -74,6 +74,13 @@ Example usage:
"Use this flag to perform a dry run, which will yield the YAML of the job without creating it.",
)

cmd.Flags().StringP(
"base-image-override",
"i",
"",
"Optional custom repository URI to override managed-scripts base image. Example: base-image-override=quay.io/foobar/managed-scripts:latest.",
)

return cmd
}

Expand Down Expand Up @@ -115,11 +122,18 @@ func runCreateTestJob(cmd *cobra.Command, args []string) error {
return err
}

// Base image override flag
baseImageOverrideFlag, err := cmd.Flags().GetString("base-image-override")
if err != nil {
return err
}

// raw flag
rawFlag, err := cmd.Flags().GetBool("raw")
if err != nil {
return err
}

// ======== Initialize backplaneURL ========
bpConfig, err := config.GetBackplaneConfiguration()
if err != nil {
Expand Down Expand Up @@ -161,7 +175,11 @@ func runCreateTestJob(cmd *cobra.Command, args []string) error {
return err
}

cj.Parameters = &backplaneApi.CreateTestJob_Parameters{AdditionalProperties: parsedParams}
if baseImageOverrideFlag != "" {
cj.BaseImageOverride = &baseImageOverrideFlag
}

cj.Parameters = &parsedParams

// ======== Call Endpoint ========
resp, err := client.CreateTestScriptRun(context.TODO(), clusterID, *cj)
Expand Down
16 changes: 16 additions & 0 deletions cmd/ocm-backplane/testJob/createTestJob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ var _ = Describe("testJob create command", func() {
Expect(err).To(BeNil())
})

It("should respect the base image when supplied as a flag", func() {
baseImgOverride := "quay.io/foo/bar"
mockOcmInterface.EXPECT().IsProduction().Return(false, nil)
// It should query for the internal cluster id first
mockOcmInterface.EXPECT().GetTargetCluster(testClusterID).Return(trueClusterID, testClusterID, nil)
mockOcmInterface.EXPECT().IsClusterHibernating(gomock.Eq(trueClusterID)).Return(false, nil).AnyTimes()
mockClientUtil.EXPECT().MakeRawBackplaneAPIClient(proxyURI).Return(mockClient, nil)
mockOcmInterface.EXPECT().GetOCMAccessToken().Return(&testToken, nil).AnyTimes()
mockClient.EXPECT().CreateTestScriptRun(gomock.Any(), trueClusterID, gomock.Any()).Return(fakeResp, nil)

sut.SetArgs([]string{"create", "--cluster-id", testClusterID, "--base-image-override", baseImgOverride})
err := sut.Execute()

Expect(err).To(BeNil())
})

It("Should able use the current logged in cluster if non specified and retrieve from config file", func() {
os.Setenv(info.BackplaneURLEnvName, "https://api-backplane.apps.something.com")
mockOcmInterface.EXPECT().IsProduction().Return(false, nil)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/onsi/gomega v1.27.10
github.com/openshift-online/ocm-cli v0.1.66
github.com/openshift-online/ocm-sdk-go v0.1.369
github.com/openshift/backplane-api v0.0.0-20230615010608-391cd2c4bbd8
github.com/openshift/backplane-api v0.0.0-20230919035427-a52e4ae498fb
github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
github.com/sirupsen/logrus v1.9.3
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw=
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc=
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand All @@ -52,6 +55,7 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/aws/aws-sdk-go-v2 v1.21.0 h1:gMT0IW+03wtYJhRqTVYn0wLzwdnK9sRMcxmtfGzRdJc=
github.com/aws/aws-sdk-go-v2 v1.21.0/go.mod h1:/RfNgGmRxI+iFOB1OeJUyxiU+9s88k3pfHvDagGEp0M=
github.com/aws/aws-sdk-go-v2/config v1.18.42 h1:28jHROB27xZwU0CB88giDSjz7M1Sba3olb5JBGwina8=
Expand Down Expand Up @@ -445,6 +449,8 @@ github.com/openshift/api v0.0.0-20221018124113-7edcfe3c76cb h1:QsBjYe5UfHIZi/3SM
github.com/openshift/api v0.0.0-20221018124113-7edcfe3c76cb/go.mod h1:JRz+ZvTqu9u7t6suhhPTacbFl5K65Y6rJbNM7HjWA3g=
github.com/openshift/backplane-api v0.0.0-20230615010608-391cd2c4bbd8 h1:SPGOXH1l1Cy0Q3dboU1e/OX3KN29bRy/DbHfA9eq090=
github.com/openshift/backplane-api v0.0.0-20230615010608-391cd2c4bbd8/go.mod h1:RuJZpJy45AJnkp7A0ZPTZhLOVkCGDLI6cGknKvp65LE=
github.com/openshift/backplane-api v0.0.0-20230919035427-a52e4ae498fb h1:hs/QQB+1gHpFozwc0lXIy+V7iMkzkkJSKdCaCumjw8Q=
github.com/openshift/backplane-api v0.0.0-20230919035427-a52e4ae498fb/go.mod h1:RuJZpJy45AJnkp7A0ZPTZhLOVkCGDLI6cGknKvp65LE=
github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c h1:CV76yFOTXmq9VciBR3Bve5ZWzSxdft7gaMVB3kS0rwg=
github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c/go.mod h1:lFMO8mLHXWFzSdYvGNo8ivF9SfF6zInA8ZGw4phRnUE=
github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=
Expand Down
24 changes: 2 additions & 22 deletions pkg/client/mocks/ClientMock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 2 additions & 22 deletions pkg/client/mocks/ClientWithResponsesMock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1deb1f7

Please sign in to comment.