Skip to content
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

K8S 1.25 Update #200

Merged
merged 13 commits into from
Oct 14, 2022
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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ~1.18
go-version: ~1.19
id: go

- name: Check out code into the Go module directory
Expand Down Expand Up @@ -56,7 +56,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ~1.18
go-version: ~1.19
id: go

- name: Check out code into the Go module directory
Expand All @@ -65,7 +65,7 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.45.2
version: v1.48.0

go-apidiff:
name: go-apidiff
Expand All @@ -76,7 +76,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ~1.18
go-version: ~1.19
id: go

- name: Check out code into the Go module directory
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ~1.18
go-version: ~1.19

- name: Create release
run: |
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM --platform=$BUILDPLATFORM golang:1.18 as builder
FROM --platform=$BUILDPLATFORM golang:1.19 as builder
ARG TARGETOS
ARG TARGETARCH

Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ build:

.PHONY: setup-lint
setup-lint: ## Setup the lint
fetch golangci-lint 1.45.2
fetch golangci-lint 1.48.0

# Run various checks against code
.PHONY: lint
lint: setup-lint
golangci-lint run


.PHONY: fix
fix: setup-lint ## Fixup files in the repo.
go mod tidy
Expand Down
259 changes: 156 additions & 103 deletions go.mod

Large diffs are not rendered by default.

1,192 changes: 932 additions & 260 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var (
)
)

//RegisterBuildInfo registers buildInfo Collector to be included in metrics collection
// RegisterBuildInfo registers buildInfo Collector to be included in metrics collection
func RegisterBuildInfo(r prometheus.Registerer) {
buildInfo.Set(1)
r.MustRegister(buildInfo)
Expand Down
13 changes: 6 additions & 7 deletions internal/testutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -95,15 +94,15 @@ func ReplaceInFile(path, old, new string) error {
if err != nil {
return err
}
b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
if err != nil {
return err
}
if !strings.Contains(string(b), old) {
return errors.New("unable to find the content to be replaced")
}
s := strings.Replace(string(b), old, new, -1)
err = ioutil.WriteFile(path, []byte(s), info.Mode())
err = os.WriteFile(path, []byte(s), info.Mode())
if err != nil {
return err
}
Expand All @@ -122,15 +121,15 @@ func ReplaceRegexInFile(path, match, replace string) error {
if err != nil {
return err
}
b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
if err != nil {
return err
}
s := matcher.ReplaceAllString(string(b), replace)
if s == string(b) {
return errors.New("unable to find the content to be replaced")
}
err = ioutil.WriteFile(path, []byte(s), info.Mode())
err = os.WriteFile(path, []byte(s), info.Mode())
if err != nil {
return err
}
Expand All @@ -142,7 +141,7 @@ func ReplaceRegexInFile(path, match, replace string) error {
// todo(camilamacedo86): this func exists in upstream/kb but there the error is not thrown. We need to
// push this change. See: https://github.com/kubernetes-sigs/kubebuilder/blob/master/test/e2e/utils/util.go
func UncommentCode(filename, target, prefix string) error {
content, err := ioutil.ReadFile(filename)
content, err := os.ReadFile(filename)
if err != nil {
return err
}
Expand Down Expand Up @@ -184,5 +183,5 @@ func UncommentCode(filename, target, prefix string) error {
}
// false positive
// nolint:gosec
return ioutil.WriteFile(filename, out.Bytes(), 0644)
return os.WriteFile(filename, out.Bytes(), 0644)
}
23 changes: 11 additions & 12 deletions pkg/annotation/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,22 @@ limitations under the License.
//
// To disable hooks based on annotations the InstallDisableHooks is passed to the reconciler as an option.
//
// r, err := reconciler.New(
// reconciler.WithChart(*w.Chart),
// reconciler.WithGroupVersionKind(w.GroupVersionKind),
// reconciler.WithInstallAnnotations(annotation.InstallDisableHook{}),
// )
// r, err := reconciler.New(
// reconciler.WithChart(*w.Chart),
// reconciler.WithGroupVersionKind(w.GroupVersionKind),
// reconciler.WithInstallAnnotations(annotation.InstallDisableHook{}),
// )
//
// If the reconciler detects an annotation named "helm.sdk.operatorframework.io/install-disable-hooks"
// on the watched custom resource it sets the install.DisableHooks option to the annotations value. For more information
// take a look at the InstallDisableHooks.InstallOption method.
//
// kind: OperatorHelmKind
// apiVersion: test.example.com/v1
// metadata:
// name: nginx-sample
// annotations:
// "helm.sdk.operatorframework.io/install-disable-hooks": true
//
// kind: OperatorHelmKind
// apiVersion: test.example.com/v1
// metadata:
// name: nginx-sample
// annotations:
// "helm.sdk.operatorframework.io/install-disable-hooks": true
package annotation

import (
Expand Down
13 changes: 6 additions & 7 deletions pkg/plugins/helm/v1/chartutil/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package chartutil
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -52,7 +51,7 @@ type Options struct {
// NewChart creates a new helm chart for the project from helm's default template.
// It returns a chart.Chart that references the newly created chart or an error.
func NewChart(name string) (*chart.Chart, error) {
tmpDir, err := ioutil.TempDir("", "osdk-helm-chart")
tmpDir, err := os.MkdirTemp("", "osdk-helm-chart")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -86,22 +85,22 @@ func NewChart(name string) (*chart.Chart, error) {
// If opts.Repo is not specified, the following chart reference formats are supported:
//
// - <repoName>/<chartName>: Fetch the helm chart named chartName from the helm
// chart repository named repoName, as specified in the
// $HELM_HOME/repositories/repositories.yaml file.
// chart repository named repoName, as specified in the
// $HELM_HOME/repositories/repositories.yaml file.
//
// - <url>: Fetch the helm chart archive at the specified URL.
//
// If opts.Repo is specified, only one chart reference format is supported:
//
// - <chartName>: Fetch the helm chart named chartName in the helm chart repository
// specified by opts.Repo
// specified by opts.Repo
//
// If opts.Version is not set, it will fetch the latest available version of the helm
// chart. Otherwise, it will fetch the specified version.
// opts.Version is not used when opts.Chart itself refers to a specific version, for
// example when it is a local path or a URL.
func LoadChart(opts Options) (*chart.Chart, error) {
tmpDir, err := ioutil.TempDir("", "osdk-helm-chart")
tmpDir, err := os.MkdirTemp("", "osdk-helm-chart")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -152,7 +151,7 @@ func downloadChart(destDir string, opts Options) (string, error) {

// ScaffoldChart scaffolds the provided chart.Chart to a known directory relative to projectDir
//
// It also fetches the dependencies and reloads the chart.Chart
// # It also fetches the dependencies and reloads the chart.Chart
//
// It returns the reloaded chart, the relative path, or an error.
func ScaffoldChart(chrt *chart.Chart, projectDir string) (*chart.Chart, string, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (f *Dockerfile) SetTemplateDefaults() error {
// `api/` and `controller/` they would have to be added.

const dockerfileTemplate = `# Build the manager binary
FROM golang:1.18 as builder
FROM golang:1.19 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (f *GoMod) SetTemplateDefaults() error {
const goModTemplate = `
module {{ .Repo }}

go 1.18
go 1.19

require (
sigs.k8s.io/controller-runtime {{ .ControllerRuntimeVersion }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const makefileTemplate = `
# Image URL to use all building/pushing image targets
IMG ?= {{ .Image }}
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.24.2
ENVTEST_K8S_VERSION = 1.25.0

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down
5 changes: 2 additions & 3 deletions pkg/plugins/util/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -47,7 +46,7 @@ func RemoveKustomizeCRDManifests() error {
return err
}
}
children, err := ioutil.ReadDir(configPatchesDir)
children, err := os.ReadDir(configPatchesDir)
if err == nil && len(children) == 0 {
if err := os.RemoveAll(configPatchesDir); err != nil {
return err
Expand All @@ -61,7 +60,7 @@ func RemoveKustomizeCRDManifests() error {
func UpdateKustomizationsCreateAPI() error {

crdKFile := filepath.Join("config", "crd", "kustomization.yaml")
if crdKBytes, err := ioutil.ReadFile(crdKFile); err != nil && !errors.Is(err, os.ErrNotExist) {
if crdKBytes, err := os.ReadFile(crdKFile); err != nil && !errors.Is(err, os.ErrNotExist) {
log.Debugf("Error reading kustomization for substitution: %v", err)
} else if err == nil {
if bytes.Contains(crdKBytes, []byte("[WEBHOOK]")) || bytes.Contains(crdKBytes, []byte("[CERTMANAGER]")) {
Expand Down
13 changes: 6 additions & 7 deletions pkg/plugins/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package util

import (
"errors"
"io/ioutil"
"os"
"regexp"
"strings"
Expand All @@ -32,15 +31,15 @@ func ReplaceInFile(path, old, new string) error {
if err != nil {
return err
}
b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
if err != nil {
return err
}
if !strings.Contains(string(b), old) {
return errors.New("unable to find the content to be replaced")
}
s := strings.Replace(string(b), old, new, -1)
err = ioutil.WriteFile(path, []byte(s), info.Mode())
err = os.WriteFile(path, []byte(s), info.Mode())
if err != nil {
return err
}
Expand All @@ -56,15 +55,15 @@ func ReplaceRegexInFile(path, match, replace string) error {
if err != nil {
return err
}
b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
if err != nil {
return err
}
s := matcher.ReplaceAllString(string(b), replace)
if s == string(b) {
return errors.New("unable to find the content to be replaced")
}
err = ioutil.WriteFile(path, []byte(s), info.Mode())
err = os.WriteFile(path, []byte(s), info.Mode())
if err != nil {
return err
}
Expand All @@ -73,13 +72,13 @@ func ReplaceRegexInFile(path, match, replace string) error {

// InsertCode searches target content in the file and insert `toInsert` after the target.
func InsertCode(filename, target, code string) error {
contents, err := ioutil.ReadFile(filename)
contents, err := os.ReadFile(filename)
if err != nil {
return err
}
idx := strings.Index(string(contents), target)
out := string(contents[:idx+len(target)]) + code + string(contents[idx+len(target):])
// false positive
// nolint:gosec
return ioutil.WriteFile(filename, []byte(out), 0644)
return os.WriteFile(filename, []byte(out), 0644)
}
3 changes: 1 addition & 2 deletions pkg/watches/watches.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"text/template"

Expand Down Expand Up @@ -63,7 +62,7 @@ func Load(path string) ([]Watch, error) {
}

func LoadReader(reader io.Reader) ([]Watch, error) {
b, err := ioutil.ReadAll(reader)
b, err := io.ReadAll(reader)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/watches/watches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package watches

import (
"bytes"
"io/ioutil"
"os"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -316,7 +315,7 @@ var _ = Describe("Load", func() {
},
}

f, err := ioutil.TempFile("", "osdk-test-load")
f, err := os.CreateTemp("", "osdk-test-load")
Expect(err).NotTo(HaveOccurred())

defer removeFile(f)
Expand Down
2 changes: 1 addition & 1 deletion testdata/hybrid/memcached-operator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.18 as builder
FROM golang:1.19 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
2 changes: 1 addition & 1 deletion testdata/hybrid/memcached-operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Image URL to use all building/pushing image targets
IMG ?= controller:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.24.2
ENVTEST_K8S_VERSION = 1.25.0

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down
Loading