Skip to content

Commit

Permalink
chore(cmd,pkg): skip build attempt when no artifacts are supported.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
  • Loading branch information
FedeDP authored and poiana committed Oct 10, 2023
1 parent ed32894 commit 9e7e4ac
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion cmd/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ func NewDockerCmd(rootOpts *RootOptions, rootFlags *pflag.FlagSet) *cobra.Comman
Run: func(c *cobra.Command, args []string) {
slog.With("processor", c.Name()).Info("driver building, it will take a few seconds")
if !configOptions.DryRun {
if err := driverbuilder.NewDockerBuildProcessor(viper.GetInt("timeout"), viper.GetString("proxy")).Start(rootOpts.ToBuild()); err != nil {
b := rootOpts.ToBuild()
if !b.HasOutputs() {
return
}
if err := driverbuilder.NewDockerBuildProcessor(viper.GetInt("timeout"), viper.GetString("proxy")).Start(b); err != nil {
slog.With("err", err.Error()).Error("exiting")
os.Exit(1)
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func NewKubernetesCmd(rootOpts *RootOptions, rootFlags *pflag.FlagSet) *cobra.Co
func kubernetesRun(cmd *cobra.Command, args []string, kubefactory factory.Factory, rootOpts *RootOptions) error {
f := cmd.Flags()
b := rootOpts.ToBuild()
if !b.HasOutputs() {
return nil
}

namespaceStr, err := f.GetString("namespace")
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions cmd/kubernetes_in_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func NewKubernetesInClusterCmd(rootOpts *RootOptions, rootFlags *pflag.FlagSet)

func kubernetesInClusterRun(_ *cobra.Command, _ []string, kubeConfig *rest.Config, rootOpts *RootOptions) error {
b := rootOpts.ToBuild()
if !b.HasOutputs() {
return nil
}

kc, err := kubernetes.NewForConfig(kubeConfig)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions cmd/root_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,8 @@ func (ro *RootOptions) ToBuild() *builder.Build {
}
if len(build.ProbeFilePath) > 0 && !kr.SupportsProbe() {
build.ProbeFilePath = ""
slog.Warn("Skipping build attempt of module for unsupported kernel release", "kernelrelease", kr.String())
slog.Warn("Skipping build attempt of probe for unsupported kernel release", "kernelrelease", kr.String())
}

return build
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/driverbuilder/builder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ func (b *Build) ClientForRegistry(registry string) *auth.Client {

return client
}

func (b *Build) HasOutputs() bool {
return b.ModuleFilePath != "" || b.ProbeFilePath != ""
}

0 comments on commit 9e7e4ac

Please sign in to comment.