Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
🌱 bump k8s, helm-operator-plugins, of/operator-registry, and of/api
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Lanford <[email protected]>
  • Loading branch information
joelanford committed Jan 12, 2024
1 parent 1d284f9 commit ffc1f61
Show file tree
Hide file tree
Showing 22 changed files with 462 additions and 889 deletions.
8 changes: 4 additions & 4 deletions .bingo/Variables.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.8. DO NOT EDIT.
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.9. DO NOT EDIT.
# All tools are designed to be build inside $GOBIN.
BINGO_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
GOPATH ?= $(shell go env GOPATH)
Expand Down Expand Up @@ -29,11 +29,11 @@ $(CONTROLLER_GEN): $(BINGO_DIR)/controller-gen.mod
@echo "(re)installing $(GOBIN)/controller-gen-v0.12.0"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=controller-gen.mod -o=$(GOBIN)/controller-gen-v0.12.0 "sigs.k8s.io/controller-tools/cmd/controller-gen"

GINKGO := $(GOBIN)/ginkgo-v2.13.0
GINKGO := $(GOBIN)/ginkgo-v2.13.2
$(GINKGO): $(BINGO_DIR)/ginkgo.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/ginkgo-v2.13.0"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=ginkgo.mod -o=$(GOBIN)/ginkgo-v2.13.0 "github.com/onsi/ginkgo/v2/ginkgo"
@echo "(re)installing $(GOBIN)/ginkgo-v2.13.2"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=ginkgo.mod -o=$(GOBIN)/ginkgo-v2.13.2 "github.com/onsi/ginkgo/v2/ginkgo"

GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.53.2
$(GOLANGCI_LINT): $(BINGO_DIR)/golangci-lint.mod
Expand Down
2 changes: 1 addition & 1 deletion .bingo/ginkgo.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.20

require github.com/onsi/ginkgo/v2 v2.13.0 // ginkgo
require github.com/onsi/ginkgo/v2 v2.13.2 // ginkgo
4 changes: 4 additions & 0 deletions .bingo/ginkgo.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ github.com/onsi/ginkgo/v2 v2.12.0 h1:UIVDowFPwpg6yMUpPjGkYvf06K3RAiJXUhCxEwQVHRI
github.com/onsi/ginkgo/v2 v2.12.0/go.mod h1:ZNEzXISYlqpb8S36iN71ifqLi3vVD1rVJGvWRCJOUpQ=
github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4=
github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o=
github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs=
github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
Expand All @@ -25,6 +27,8 @@ golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss=
golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM=
golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc=
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 2 additions & 2 deletions .bingo/variables.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.8. DO NOT EDIT.
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.9. DO NOT EDIT.
# All tools are designed to be build inside $GOBIN.
# Those variables will work only until 'bingo get' was invoked, or if tools were installed via Makefile's Variables.mk.
GOBIN=${GOBIN:=$(go env GOBIN)}
Expand All @@ -12,7 +12,7 @@ BINGO="${GOBIN}/bingo-v0.8.0"

CONTROLLER_GEN="${GOBIN}/controller-gen-v0.12.0"

GINKGO="${GOBIN}/ginkgo-v2.13.0"
GINKGO="${GOBIN}/ginkgo-v2.13.2"

GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.53.2"

Expand Down
110 changes: 66 additions & 44 deletions cmd/core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ import (
"k8s.io/apimachinery/pkg/selection"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/kube-aggregator/pkg/apis/apiregistration"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/cluster"
"sigs.k8s.io/controller-runtime/pkg/client"
crfinalizer "sigs.k8s.io/controller-runtime/pkg/finalizer"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"

rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
"github.com/operator-framework/rukpak/internal/controllers/bundle"
Expand Down Expand Up @@ -128,38 +130,38 @@ func main() {
systemNamespace = util.PodNamespace()
}

systemNsCluster, err := cluster.New(cfg, func(opts *cluster.Options) {
opts.Scheme = scheme
opts.Namespace = systemNamespace
// We need to create the cache and client in advance because
// controller-runtime's manager doesn't allow us to specify
// extra metrics handlers after the manager has been created,
// and the upload manager handler needs a client.
//
// We configure the manager to use this cache and client rather
// than creating its own.
mgrCache, err := cache.New(cfg, cache.Options{
Scheme: scheme,
ByObject: map[client.Object]cache.ByObject{
&rukpakv1alpha1.BundleDeployment{}: {},
&rukpakv1alpha1.Bundle{}: {},
},
DefaultNamespaces: map[string]cache.Config{
systemNamespace: {},
cache.AllNamespaces: {LabelSelector: dependentSelector},
},
})
if err != nil {
setupLog.Error(err, "unable to create system namespace cluster")
setupLog.Error(err, "unable to create manager cache")
os.Exit(1)
}
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
MetricsBindAddress: httpBindAddr,
Port: 9443,
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "core.rukpak.io",
NewCache: cache.BuilderWithOptions(cache.Options{
SelectorsByObject: cache.SelectorsByObject{
&rukpakv1alpha1.BundleDeployment{}: {},
&rukpakv1alpha1.Bundle{}: {},
},
DefaultSelector: cache.ObjectSelector{
Label: dependentSelector,
},
}),

mgrClient, err := client.New(cfg, client.Options{
Scheme: scheme,
Cache: &client.CacheOptions{
Reader: mgrCache,
Unstructured: false,
},
})
if err != nil {
setupLog.Error(err, "unable to create manager")
os.Exit(1)
}

if err := mgr.Add(systemNsCluster); err != nil {
setupLog.Error(err, "unable to add system namespace cluster to manager")
setupLog.Error(err, "unable to create manager client")
os.Exit(1)
}

Expand All @@ -174,6 +176,30 @@ func main() {
URL: *storageURL,
}

mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
NewClient: func(_ *rest.Config, _ client.Options) (client.Client, error) { return mgrClient, nil },
NewCache: func(_ *rest.Config, _ cache.Options) (cache.Cache, error) { return mgrCache, nil },
Metrics: server.Options{
BindAddress: httpBindAddr,
ExtraHandlers: map[string]http.Handler{
// NOTE: ExtraHandlers aren't actually metrics-specific. We can run
// whatever handlers we want on the existing webserver that
// controller-runtime runs when MetricsBindAddress is configured on the
// manager.
"/bundles/": httpLogger(localStorage),
"/uploads/": httpLogger(uploadmgr.NewUploadHandler(mgrClient, uploadStorageDirectory)),
},
},
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "core.rukpak.io",
})
if err != nil {
setupLog.Error(err, "unable to create manager")
os.Exit(1)
}

var rootCAs *x509.CertPool
if bundleCAFile != "" {
var err error
Expand All @@ -189,18 +215,6 @@ func main() {
)
bundleStorage := storage.WithFallbackLoader(localStorage, httpLoader)

// NOTE: AddMetricsExtraHandler isn't actually metrics-specific. We can run
// whatever handlers we want on the existing webserver that
// controller-runtime runs when MetricsBindAddress is configured on the
// manager.
if err := mgr.AddMetricsExtraHandler("/bundles/", httpLogger(localStorage)); err != nil {
setupLog.Error(err, "unable to add bundles http handler to manager")
os.Exit(1)
}
if err := mgr.AddMetricsExtraHandler("/uploads/", httpLogger(uploadmgr.NewUploadHandler(mgr.GetClient(), uploadStorageDirectory))); err != nil {
setupLog.Error(err, "unable to add uploads http handler to manager")
os.Exit(1)
}
if err := mgr.Add(uploadmgr.NewBundleGC(mgr.GetCache(), uploadStorageDirectory, uploadStorageSyncInterval)); err != nil {
setupLog.Error(err, "unable to add bundle garbage collector to manager")
os.Exit(1)
Expand All @@ -225,7 +239,7 @@ func main() {
os.Exit(1)
}

unpacker, err := source.NewDefaultUnpacker(systemNsCluster, systemNamespace, unpackImage, baseUploadManagerURL, rootCAs)
unpacker, err := source.NewDefaultUnpacker(mgr, systemNamespace, unpackImage, baseUploadManagerURL, rootCAs)
if err != nil {
setupLog.Error(err, "unable to setup bundle unpacker")
os.Exit(1)
Expand All @@ -237,15 +251,23 @@ func main() {
bundle.WithStorage(bundleStorage),
}

cfgGetter := helmclient.NewActionConfigGetter(mgr.GetConfig(), mgr.GetRESTMapper(), mgr.GetLogger())
acg := helmclient.NewActionClientGetter(cfgGetter)
cfgGetter, err := helmclient.NewActionConfigGetter(mgr.GetConfig(), mgr.GetRESTMapper(), mgr.GetLogger())
if err != nil {
setupLog.Error(err, "unable to create action config getter")
os.Exit(1)
}
acg, err := helmclient.NewActionClientGetter(cfgGetter)
if err != nil {
setupLog.Error(err, "unable to create action client getter")
os.Exit(1)
}
commonBDProvisionerOptions := []bundledeployment.Option{
bundledeployment.WithReleaseNamespace(systemNamespace),
bundledeployment.WithActionClientGetter(acg),
bundledeployment.WithStorage(bundleStorage),
}

if err := bundle.SetupWithManager(mgr, systemNsCluster.GetCache(), systemNamespace, append(
if err := bundle.SetupWithManager(mgr, systemNamespace, append(
commonBundleProvisionerOptions,
bundle.WithProvisionerID(plain.ProvisionerID),
bundle.WithHandler(bundle.HandlerFunc(plain.HandleBundle)),
Expand All @@ -254,7 +276,7 @@ func main() {
os.Exit(1)
}

if err := bundle.SetupWithManager(mgr, systemNsCluster.GetCache(), systemNamespace, append(
if err := bundle.SetupWithManager(mgr, systemNamespace, append(
commonBundleProvisionerOptions,
bundle.WithProvisionerID(registry.ProvisionerID),
bundle.WithHandler(bundle.HandlerFunc(registry.HandleBundle)),
Expand Down
11 changes: 3 additions & 8 deletions cmd/crdvalidator/handlers/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ type CrdValidator struct {

func NewCrdValidator(log logr.Logger, client client.Client) CrdValidator {
return CrdValidator{
log: log.V(1).WithName("crdhandler"), // Default to non-verbose logs
client: client,
log: log.V(1).WithName("crdhandler"), // Default to non-verbose logs
client: client,
decoder: admission.NewDecoder(client.Scheme()),
}
}

Expand Down Expand Up @@ -74,12 +75,6 @@ func (cv *CrdValidator) Handle(ctx context.Context, req admission.Request) admis
return admission.Allowed("")
}

// InjectDecoder injects a decoder for the CrdValidator.
func (cv *CrdValidator) InjectDecoder(d *admission.Decoder) error {
cv.decoder = d
return nil
}

// disabled takes a CRD and checks its content to see crdvalidator
// is disabled explicitly
func disabled(crd *apiextensionsv1.CustomResourceDefinition) bool {
Expand Down
19 changes: 13 additions & 6 deletions cmd/crdvalidator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import (

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
"sigs.k8s.io/controller-runtime/pkg/webhook"
Expand All @@ -48,9 +50,16 @@ func init() {

func main() {
var enableHTTP2 bool

flag.BoolVar(&enableHTTP2, "enable-http2", enableHTTP2, "If HTTP/2 should be enabled for the webhook servers.")

opts := zap.Options{
Development: true,
}
opts.BindFlags(flag.CommandLine)

flag.Parse()
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

// Setup webhook options
disableHTTP2 := func(c *tls.Config) {
if enableHTTP2 {
Expand All @@ -59,9 +68,10 @@ func main() {
c.NextProtos = []string{"http/1.1"}
}

webhookServer := &webhook.Server{
webhookServer := webhook.NewServer(webhook.Options{
TLSOpts: []func(config *tls.Config){disableHTTP2},
}
CertDir: defaultCertDir,
})

entryLog.Info("setting up manager")
mgr, err := manager.New(config.GetConfigOrDie(), manager.Options{Scheme: scheme, WebhookServer: webhookServer})
Expand All @@ -73,9 +83,6 @@ func main() {
entryLog.Info("setting up webhook server")
hookServer := mgr.GetWebhookServer()

// Point to where cert-mgr is placing the cert
hookServer.CertDir = defaultCertDir

// Register CRD validation handler
entryLog.Info("registering webhooks to the webhook server")
crdValidatorHandler := handlers.NewCrdValidator(entryLog, mgr.GetClient())
Expand Down
Loading

0 comments on commit ffc1f61

Please sign in to comment.