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

bump k8s to 1.21 #160

Merged
merged 1 commit into from
Jun 30, 2021
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 examples/guestbook-operator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module sigs.k8s.io/kubebuilder-declarative-pattern/examples/guestbook-operator
go 1.13

require (
github.com/go-logr/logr v0.3.0
k8s.io/apimachinery v0.20.1
k8s.io/client-go v0.20.1
sigs.k8s.io/controller-runtime v0.8.0
github.com/go-logr/logr v0.4.0
k8s.io/apimachinery v0.21.1
k8s.io/client-go v0.21.1
sigs.k8s.io/controller-runtime v0.9.0
sigs.k8s.io/kubebuilder-declarative-pattern v0.0.0
)

Expand Down
341 changes: 155 additions & 186 deletions examples/guestbook-operator/go.sum

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ require (
github.com/blang/semver/v4 v4.0.0
github.com/evanphx/json-patch/v5 v5.1.0
github.com/go-git/go-git/v5 v5.1.0
github.com/go-logr/logr v0.3.0
github.com/go-logr/logr v0.4.0
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/prometheus/client_golang v1.7.1
github.com/stretchr/testify v1.6.1
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0
golang.org/x/tools v0.0.0-20200714190737-9048b464a08d
k8s.io/api v0.20.1
k8s.io/apimachinery v0.20.1
k8s.io/cli-runtime v0.20.1
k8s.io/client-go v0.20.1
github.com/prometheus/client_golang v1.11.0
github.com/stretchr/testify v1.7.0
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83
golang.org/x/tools v0.1.0
k8s.io/api v0.21.1
k8s.io/apimachinery v0.21.1
k8s.io/cli-runtime v0.21.1
k8s.io/client-go v0.21.1
k8s.io/klog v1.0.0
k8s.io/kubectl v0.20.1
k8s.io/kubectl v0.21.1
sigs.k8s.io/cli-utils v0.16.0
sigs.k8s.io/controller-runtime v0.8.0
sigs.k8s.io/kustomize/api v0.3.2
sigs.k8s.io/controller-runtime v0.9.0
sigs.k8s.io/kustomize/api v0.8.8
sigs.k8s.io/yaml v1.2.0
)
343 changes: 155 additions & 188 deletions go.sum

Large diffs are not rendered by default.

54 changes: 34 additions & 20 deletions pkg/patterns/declarative/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import (
"bytes"
"context"
"errors"
"os"
"os/exec"
"path/filepath"
"io/ioutil"
"strings"
"testing"
"time"
Expand All @@ -32,6 +30,7 @@ import (
core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -242,10 +241,10 @@ func TestReconcileFailedWith(t *testing.T) {
// and point that path.
func TestAddIfNotPresent(t *testing.T) {
const defKubectlPath = "/usr/local/kubebuilder/bin"
var kubectlPath string

// Run local kube-apiserver & etecd
testEnv := envtest.Environment{}

restConf, err := testEnv.Start()
if err != nil {
t.Log("Maybe, you have to make sure control plane binaries" + " " +
Expand All @@ -256,6 +255,12 @@ func TestAddIfNotPresent(t *testing.T) {
t.Error(err)
}

// Add user for test
user, err := testEnv.AddUser(envtest.User{Name: "default", Groups: []string{"system:masters"}}, &rest.Config{})
if err != nil {
t.Error(err)
}

// Create manager
mgrOpt := manager.Options{}
mgr, err := manager.New(restConf, mgrOpt)
Expand All @@ -268,11 +273,9 @@ func TestAddIfNotPresent(t *testing.T) {
_ = mgr.GetCache().Start(ctx)
}()

// Set up kubectl command
if envPath := os.Getenv("KUBEBUILDER_ASSETS"); envPath != "" {
kubectlPath = filepath.Join(envPath, "kubectl")
} else {
kubectlPath = filepath.Join("/usr/local/kubebuilder/bin", "kubectl")
ctl, err := user.Kubectl()
if err != nil {
t.Error(err)
}

// kubectl arg for "kubectl apply"
Expand Down Expand Up @@ -488,7 +491,6 @@ func TestAddIfNotPresent(t *testing.T) {
globalObjectTracker.SetMetricsDuration(st.metricsDuration)

for i, yobjList := range st.objects {
var cmd *exec.Cmd
var stdout bytes.Buffer
var stderr bytes.Buffer
var cmdArgs []string
Expand Down Expand Up @@ -529,26 +531,38 @@ func TestAddIfNotPresent(t *testing.T) {
t.Error(err)
}

tmpManifests, err := ioutil.TempFile(t.TempDir(), "tmp-manifests-*.yaml")
if err != nil {
t.Error(err)
}
_, err = tmpManifests.WriteString(yobj)
if err != nil {
tmpManifests.Close()
t.Error(err)
}
err = tmpManifests.Close()
if err != nil {
t.Error(err)
}

// Set up kubectl command
if st.actions[i] != "Delete" {
if len(st.defaultNamespace) != 0 {
cmdArgs = append(applyArgs, "-n", st.defaultNamespace, "-f", "-")
cmdArgs = append(applyArgs, "-n", st.defaultNamespace, "-f", tmpManifests.Name())
} else {
cmdArgs = append(applyArgs, "-f", "-")
cmdArgs = append(applyArgs, "-f", tmpManifests.Name())
}
} else {
if len(st.defaultNamespace) != 0 {
cmdArgs = append(deleteArgs, "-n", st.defaultNamespace, "-f", "-")
cmdArgs = append(deleteArgs, "-n", st.defaultNamespace, "-f", tmpManifests.Name())
} else {
cmdArgs = append(deleteArgs, "-f", "-")
cmdArgs = append(deleteArgs, "-f", tmpManifests.Name())
}
}
cmd = exec.Command(kubectlPath, cmdArgs...)
cmd.Stdin = strings.NewReader(yobj)
cmd.Stdout = &stdout
cmd.Stderr = &stderr

if err := cmd.Run(); err != nil {
stdOut, stdErr, err := ctl.Run(cmdArgs...)
if err != nil {
stdout.ReadFrom(stdOut)
stderr.ReadFrom(stdErr)
t.Logf("action: %v\n", st.actions[i])
t.Logf("stdout: %v\n", stdout.String())
t.Logf("stderr: %v\n", stderr.String())
Expand Down
4 changes: 2 additions & 2 deletions pkg/patterns/declarative/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ func (r *Reconciler) BuildDeploymentObjectsWithFs(ctx context.Context, name type
if r.IsKustomizeOptionUsed() {
// run kustomize to create final manifest
opts := krusty.MakeDefaultOptions()
k := krusty.MakeKustomizer(fs, opts)
m, err := k.Run(manifestObjects.Path)
k := krusty.MakeKustomizer(opts)
m, err := k.Run(fs, manifestObjects.Path)
if err != nil {
log.Error(err, "running kustomize to create final manifest")
return nil, fmt.Errorf("error running kustomize: %v", err)
Expand Down
18 changes: 12 additions & 6 deletions pkg/test/mocks/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@ import (
"k8s.io/client-go/tools/record"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)

// Mock Types for Reconciler tests:
type Manager struct {
client client.Client
cache cache.Cache
config rest.Config
Scheme *runtime.Scheme
eventRecorder record.EventRecorder
mapper meta.RESTMapper
client client.Client
cache cache.Cache
config rest.Config
Scheme *runtime.Scheme
eventRecorder record.EventRecorder
mapper meta.RESTMapper
controllerOptions v1alpha1.ControllerConfigurationSpec
}

var _ manager.Manager = &Manager{}
Expand All @@ -64,6 +66,10 @@ func (Manager) Start(context.Context) error {
panic("implement me")
}

func (m Manager) GetControllerOptions() v1alpha1.ControllerConfigurationSpec {
return m.controllerOptions
}

func (m Manager) GetConfig() *rest.Config {
return &m.config
}
Expand Down