-
Notifications
You must be signed in to change notification settings - Fork 35
add cli changes to move to v1beta1 #304
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 all commits
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 | ||||
---|---|---|---|---|---|---|
|
@@ -3,7 +3,7 @@ package build | |||||
import ( | ||||||
"fmt" | ||||||
|
||||||
buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" | ||||||
buildv1beta1 "github.com/shipwright-io/build/pkg/apis/build/v1beta1" | ||||||
"github.com/spf13/cobra" | ||||||
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||
|
@@ -18,8 +18,11 @@ import ( | |||||
type CreateCommand struct { | ||||||
cmd *cobra.Command // cobra command instance | ||||||
|
||||||
name string // build resource's name | ||||||
buildSpec *buildv1alpha1.BuildSpec // stores command-line flags | ||||||
name string // build resource's name | ||||||
buildSpec *buildv1beta1.BuildSpec // stores command-line flags | ||||||
dockerfile *string // For dockerfile parameter | ||||||
builderImage *string // For builder image parameter | ||||||
|
||||||
} | ||||||
|
||||||
const buildCreateLongDesc = ` | ||||||
|
@@ -54,7 +57,7 @@ func (c *CreateCommand) Validate() error { | |||||
|
||||||
// Run executes the creation of a new Build instance using flags to fill up the details. | ||||||
func (c *CreateCommand) Run(params *params.Params, io *genericclioptions.IOStreams) error { | ||||||
b := &buildv1alpha1.Build{ | ||||||
b := &buildv1beta1.Build{ | ||||||
ObjectMeta: metav1.ObjectMeta{ | ||||||
Name: c.name, | ||||||
}, | ||||||
|
@@ -63,16 +66,44 @@ func (c *CreateCommand) Run(params *params.Params, io *genericclioptions.IOStrea | |||||
|
||||||
flags.SanitizeBuildSpec(&b.Spec) | ||||||
|
||||||
// print warning with regards to source bundle image being used | ||||||
if b.Spec.Source.BundleContainer != nil && b.Spec.Source.BundleContainer.Image != "" { | ||||||
fmt.Fprintf(io.Out, "Build %q uses a source bundle image, which means source code will be transferred to a container registry. It is advised to use private images to ensure the security of the source code being uploaded.\n", c.name) | ||||||
if b.Spec.Source != nil { | ||||||
if b.Spec.Source.OCIArtifact != nil && b.Spec.Source.OCIArtifact.Image != "" { | ||||||
b.Spec.Source.Type = buildv1beta1.OCIArtifactType | ||||||
} else if b.Spec.Source.Git != nil && b.Spec.Source.Git.URL != "" { | ||||||
b.Spec.Source.Type = buildv1beta1.GitType | ||||||
} | ||||||
|
||||||
// print warning with regards to source bundle image being used | ||||||
if b.Spec.Source.OCIArtifact != nil && b.Spec.Source.OCIArtifact.Image != "" { | ||||||
fmt.Fprintf(io.Out, "Build %q uses a source bundle image, which means source code will be transferred to a container registry. It is advised to use private images to ensure the security of the source code being uploaded.\n", c.name) | ||||||
} | ||||||
} | ||||||
|
||||||
if c.dockerfile != nil && *c.dockerfile != "" { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit (not going to block on this) - you can do both checks in golang using
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @adambkaplan , I know it works with arrays, but I tried this : https://go.dev/play/p/_nEyrfl96EZ and it didn't work for pointer strings. |
||||||
dockerfileParam := buildv1beta1.ParamValue{ | ||||||
Name: "dockerfile", | ||||||
SingleValue: &buildv1beta1.SingleValue{ | ||||||
Value: c.dockerfile, | ||||||
}, | ||||||
} | ||||||
c.buildSpec.ParamValues = append(c.buildSpec.ParamValues, dockerfileParam) | ||||||
} | ||||||
|
||||||
if c.builderImage != nil && *c.builderImage != "" { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit (not blocking) - ditto on using
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @adambkaplan , I know it works with arrays, but I tried this : https://go.dev/play/p/_nEyrfl96EZ and it didn't work for pointer strings. |
||||||
builderParam := buildv1beta1.ParamValue{ | ||||||
Name: "builder-image", | ||||||
SingleValue: &buildv1beta1.SingleValue{ | ||||||
Value: c.builderImage, | ||||||
}, | ||||||
} | ||||||
c.buildSpec.ParamValues = append(c.buildSpec.ParamValues, builderParam) | ||||||
} | ||||||
|
||||||
clientset, err := params.ShipwrightClientSet() | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
if _, err := clientset.ShipwrightV1alpha1().Builds(params.Namespace()).Create(c.cmd.Context(), b, metav1.CreateOptions{}); err != nil { | ||||||
if _, err := clientset.ShipwrightV1beta1().Builds(params.Namespace()).Create(c.cmd.Context(), b, metav1.CreateOptions{}); err != nil { | ||||||
return err | ||||||
} | ||||||
fmt.Fprintf(io.Out, "Created build %q\n", c.name) | ||||||
|
@@ -89,13 +120,15 @@ func createCmd() runner.SubCommand { | |||||
|
||||||
// instantiating command-line flags and the build-spec structure which receives the informed flag | ||||||
// values, also marking certain flags as mandatory | ||||||
buildSpecFlags := flags.BuildSpecFromFlags(cmd.Flags()) | ||||||
buildSpecFlags, dockerfileFlag, builderImageFlag := flags.BuildSpecFromFlags(cmd.Flags()) | ||||||
if err := cmd.MarkFlagRequired(flags.OutputImageFlag); err != nil { | ||||||
panic(err) | ||||||
} | ||||||
|
||||||
return &CreateCommand{ | ||||||
cmd: cmd, | ||||||
buildSpec: buildSpecFlags, | ||||||
cmd: cmd, | ||||||
buildSpec: buildSpecFlags, | ||||||
dockerfile: dockerfileFlag, | ||||||
builderImage: builderImageFlag, | ||||||
} | ||||||
} |
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.
nit - ditto on use of len:
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.
@adambkaplan , I know it works with arrays, but I tried this : https://go.dev/play/p/_nEyrfl96EZ and it didn't work for pointer strings.