Skip to content

Commit

Permalink
fix: updated go version for dockerfile to build controller
Browse files Browse the repository at this point in the history
Also centralized the preferred and minimum version variables into a version file
in utils package to assist with future upgrades.

Signed-off-by: Dustin Scott <dustin.scott18@gmail.com>
  • Loading branch information
scottd018 committed Jun 20, 2022
1 parent 195eb33 commit f17e9ae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package templates

import (
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"

"github.com/vmware-tanzu-labs/operator-builder/internal/utils"
)

const (
Expand All @@ -16,6 +18,8 @@ var _ machinery.Template = &Dockerfile{}
// Dockerfile scaffolds a file that defines the containerized build process.
type Dockerfile struct {
machinery.TemplateMixin

GoVersion string
}

// SetTemplateDefaults implements file.Template.
Expand All @@ -24,15 +28,15 @@ func (f *Dockerfile) SetTemplateDefaults() error {
f.Path = defaultDockerfilePath
}

f.GoVersion = utils.GeneratedGoVersionPreferred
f.IfExistsAction = machinery.OverwriteFile

f.TemplateBody = dockerfileTemplate

return nil
}

const dockerfileTemplate = `# Build the manager binary
FROM golang:1.16 as builder
FROM golang:{{ .GoVersion }} as builder
WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
8 changes: 3 additions & 5 deletions internal/plugins/workload/v1/scaffolds/templates/gomod.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ package templates

import (
"sigs.k8s.io/kubebuilder/v3/pkg/machinery"

"github.com/vmware-tanzu-labs/operator-builder/internal/utils"
)

var _ machinery.Template = &GoMod{}

const (
GoVersionMinimum = "1.17"
)

// GoMod scaffolds a file that defines the project dependencies.
type GoMod struct {
machinery.TemplateMixin
Expand Down Expand Up @@ -57,7 +55,7 @@ func (f *GoMod) SetTemplateDefaults() error {
f.Path = "go.mod"
}

f.GoVersionMinimum = GoVersionMinimum
f.GoVersionMinimum = utils.GeneratedGoVersionMinimum
f.Dependencies = goModDependencyMap()
f.IndirectDependencies = goModIndirectDependencyMap()
f.TemplateBody = goModTemplate
Expand Down
9 changes: 9 additions & 0 deletions internal/utils/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package utils

const (
// specifies the minimum version required to build the generated project
GeneratedGoVersionMinimum = "1.17"

// specifies the preferred version
GeneratedGoVersionPreferred = "1.18"
)

0 comments on commit f17e9ae

Please sign in to comment.