Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: install
uses: actions/setup-go@v2
with:
go-version: 1.15.5
go-version: 1.16

- name: gpg init
if: github.event_name != 'pull_request'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16
- uses: actions/checkout@v2
with:
fetch-depth: 0
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16
- uses: actions/checkout@v2
with:
fetch-depth: 0
Expand All @@ -43,7 +43,7 @@ jobs:
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16
- uses: actions/checkout@v2
with:
fetch-depth: 0
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16
- uses: actions/checkout@v2
with:
fetch-depth: 0
Expand All @@ -43,7 +43,7 @@ jobs:
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16
- uses: actions/checkout@v2
with:
fetch-depth: 0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-helm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16
- uses: actions/checkout@v2
with:
fetch-depth: 0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-sanity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16
id: go
- uses: actions/checkout@v2
with:
Expand Down
4 changes: 4 additions & 0 deletions changelog/fragments/go1.16.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
entries:
- description: >
(go/v3) Upgraded Go version to 1.16.
kind: change
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/operator-framework/operator-sdk

go 1.15
go 1.16

require (
github.com/blang/semver/v4 v4.0.0
Expand All @@ -9,6 +9,7 @@ require (
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334
github.com/kr/text v0.1.0
github.com/markbates/inflect v1.0.4
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2
github.com/onsi/ginkgo v1.15.2
github.com/onsi/gomega v1.11.0
github.com/operator-framework/api v0.8.1
Expand Down Expand Up @@ -50,7 +51,7 @@ replace (
github.com/containerd/containerd => github.com/containerd/containerd v1.4.3
github.com/mattn/go-sqlite3 => github.com/mattn/go-sqlite3 v1.10.0
golang.org/x/text => golang.org/x/text v0.3.3 // Required to fix CVE-2020-14040
sigs.k8s.io/kubebuilder/v3 => sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20210511221939-53b7bf2fc477
sigs.k8s.io/kubebuilder/v3 => sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20210518234629-191170994550
)

exclude github.com/spf13/viper v1.3.2 // Required to fix CVE-2018-1098
48 changes: 4 additions & 44 deletions go.sum

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package v2
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"

Expand Down Expand Up @@ -100,6 +101,11 @@ func (mh *Memcached) Run() {
mh.uncommentDefaultKustomization()
mh.uncommentManifestsKustomization()

cmd := exec.Command("go", "mod", "tidy")
cmd.Dir = mh.ctx.Dir
_, err = mh.ctx.Run(cmd)
pkg.CheckError("Running go mod tidy", err)

log.Infof("creating the bundle")
err = mh.ctx.GenerateBundle()
pkg.CheckError("creating the bundle", err)
Expand Down
24 changes: 18 additions & 6 deletions hack/generate/samples/internal/go/v3/memcached_with_webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package v3
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"

Expand Down Expand Up @@ -100,6 +101,11 @@ func (mh *Memcached) Run() {
mh.uncommentDefaultKustomization()
mh.uncommentManifestsKustomization()

cmd := exec.Command("go", "mod", "tidy")
cmd.Dir = mh.ctx.Dir
_, err = mh.ctx.Run(cmd)
pkg.CheckError("Running go mod tidy", err)

log.Infof("creating the bundle")
err = mh.ctx.GenerateBundle()
pkg.CheckError("creating the bundle", err)
Expand Down Expand Up @@ -234,25 +240,31 @@ func (mh *Memcached) implementingController() {

// Replace reconcile content
err = util.ReplaceInFile(controllerPath,
fmt.Sprintf("_ = r.Log.WithValues(\"%s\", req.NamespacedName)", strings.ToLower(mh.ctx.Kind)),
fmt.Sprintf("log := r.Log.WithValues(\"%s\", req.NamespacedName)", strings.ToLower(mh.ctx.Kind)))
pkg.CheckError("replacing reconcile content", err)
`"sigs.k8s.io/controller-runtime/pkg/log"`,
`ctrllog "sigs.k8s.io/controller-runtime/pkg/log"`,
)
pkg.CheckError("replacing controller log import", err)
err = util.ReplaceInFile(controllerPath,
"_ = log.FromContext(ctx)",
"log := ctrllog.FromContext(ctx)",
)
pkg.CheckError("replacing controller logger construction", err)

// Add reconcile implementation
err = util.ReplaceInFile(controllerPath,
"// your logic here", reconcileFragment)
pkg.CheckError("replacing reconcile", err)
pkg.CheckError("replacing reconcile content", err)

// Add helpers funcs to the controller
err = kbtestutils.InsertCode(controllerPath,
"return ctrl.Result{}, nil\n}", controllerFuncsFragment)
pkg.CheckError("adding helpers methods in the controller", err)
pkg.CheckError("adding helper methods in the controller", err)

// Add watch for the Kind
err = util.ReplaceInFile(controllerPath,
fmt.Sprintf(watchOriginalFragment, mh.ctx.Group, mh.ctx.Version, mh.ctx.Kind),
fmt.Sprintf(watchCustomizedFragment, mh.ctx.Group, mh.ctx.Version, mh.ctx.Kind))
pkg.CheckError("replacing reconcile", err)
pkg.CheckError("replacing add controller to manager", err)
}

// nolint:gosec
Expand Down
2 changes: 1 addition & 1 deletion images/ansible-operator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM --platform=$BUILDPLATFORM golang:1.15 as builder
FROM --platform=$BUILDPLATFORM golang:1.16 as builder
ARG TARGETARCH

WORKDIR /workspace
Expand Down
2 changes: 1 addition & 1 deletion images/custom-scorecard-tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the custom-scorecard-tests binary
FROM --platform=$BUILDPLATFORM golang:1.15 as builder
FROM --platform=$BUILDPLATFORM golang:1.16 as builder
ARG TARGETARCH

WORKDIR /workspace
Expand Down
2 changes: 1 addition & 1 deletion images/helm-operator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM --platform=$BUILDPLATFORM golang:1.15 as builder
FROM --platform=$BUILDPLATFORM golang:1.16 as builder
ARG TARGETARCH

WORKDIR /workspace
Expand Down
13 changes: 11 additions & 2 deletions images/operator-sdk/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the operator-sdk binary
FROM --platform=$BUILDPLATFORM golang:1.15 as builder
FROM --platform=$BUILDPLATFORM golang:1.16 as builder
ARG TARGETARCH

WORKDIR /workspace
Expand All @@ -19,7 +19,16 @@ RUN GOOS=linux GOARCH=$TARGETARCH make build/operator-sdk
# Final image.
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3

RUN microdnf install -y golang make which
ENV GO_VERSION 1.16.4

ARG TARGETARCH
RUN microdnf install -y make which tar gzip
RUN curl -sSLo /tmp/go.tar.gz https://golang.org/dl/go${GO_VERSION}.linux-${TARGETARCH}.tar.gz \
&& rm -rf /usr/local/go \
&& tar -C /usr/local -xzf /tmp/go.tar.gz \
&& ln -sf /usr/local/go/bin/* /usr/local/bin/ \
&& rm -f /tmp/go.tar.gz \
&& go version

COPY --from=builder /workspace/build/operator-sdk /usr/local/bin/operator-sdk

Expand Down
2 changes: 1 addition & 1 deletion images/scorecard-test-kuttl/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the scorecard-test-kuttl binary
FROM --platform=$BUILDPLATFORM golang:1.15 as builder
FROM --platform=$BUILDPLATFORM golang:1.16 as builder
ARG TARGETARCH

WORKDIR /workspace
Expand Down
2 changes: 1 addition & 1 deletion images/scorecard-test/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the scorecard-test binary
FROM --platform=$BUILDPLATFORM golang:1.15 as builder
FROM --platform=$BUILDPLATFORM golang:1.16 as builder
ARG TARGETARCH

WORKDIR /workspace
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/ansible-operator/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func run(cmd *cobra.Command, f *flags.Flags) {
os.Exit(1)
}

cMap.Store(w.GroupVersionKind, &controllermap.Contents{Controller: *ctr,
cMap.Store(w.GroupVersionKind, &controllermap.Contents{Controller: *ctr, //nolint:staticcheck
WatchDependentResources: w.WatchDependentResources,
WatchClusterScopedResources: w.WatchClusterScopedResources,
OwnerWatchMap: controllermap.NewWatchMap(),
Expand Down
4 changes: 2 additions & 2 deletions testdata/go/v3/memcached-operator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.15 as builder
FROM golang:1.16 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -15,7 +15,7 @@ COPY api/ api/
COPY controllers/ controllers/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@ import (

"context"

"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
ctrllog "sigs.k8s.io/controller-runtime/pkg/log"

cachev1alpha1 "github.com/example/memcached-operator/api/v1alpha1"
)

// MemcachedReconciler reconciles a Memcached object
type MemcachedReconciler struct {
client.Client
Log logr.Logger
Scheme *runtime.Scheme
}

Expand All @@ -58,7 +57,7 @@ type MemcachedReconciler struct {
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.8.3/pkg/reconcile
func (r *MemcachedReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := r.Log.WithValues("memcached", req.NamespacedName)
log := ctrllog.FromContext(ctx)

// Fetch the Memcached instance
memcached := &cachev1alpha1.Memcached{}
Expand Down
3 changes: 1 addition & 2 deletions testdata/go/v3/memcached-operator/go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module github.com/example/memcached-operator

go 1.15
go 1.16

require (
github.com/go-logr/logr v0.3.0
github.com/onsi/ginkgo v1.14.1
github.com/onsi/gomega v1.10.2
k8s.io/api v0.20.2
Expand Down
1 change: 0 additions & 1 deletion testdata/go/v3/memcached-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func main() {

if err = (&controllers.MemcachedReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("Memcached"),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Memcached")
Expand Down
7 changes: 7 additions & 0 deletions tools/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build tools

package tools

import (
_ "github.com/maxbrunsfeld/counterfeiter/v6"
)
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Operators set the logger for all operator logging in `main.go`. To illustrate ho
package main

import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

Expand Down Expand Up @@ -191,7 +191,7 @@ An example from [`memcached_controller.go`][code_memcached_controller]:
package memcached

import (
"github.com/go-logr/logr"
ctrllog "sigs.k8s.io/controller-runtime/pkg/log"
)


Expand All @@ -203,7 +203,7 @@ type MemcachedReconciler struct {
}

func (r *MemcachedReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := r.Log.WithValues("memcached", req.NamespacedName)
log := ctrllog.FromContext(ctx)

// Fetch the Memcached instance
memcached := &cachev1alpha1.Memcached{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ weight: 1
### Prerequisites

- [git][git-tool]
- [go][go-tool] version 1.15
- [go][go-tool] version 1.16

### Download Operator SDK

Expand Down