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

🐛 More needed for podman workaround in kind-load #788

Closed
wants to merge 13 commits into from
Closed
23 changes: 17 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,16 @@ vet: #EXHELP Run go vet against code.
test: manifests generate fmt vet test-unit test-e2e #HELP Run all tests.

.PHONY: e2e
FOCUS := $(if $(TEST),-v -focus "$(TEST)")
E2E_FLAGS ?= ""
e2e: $(SETUP_ENVTEST) #EXHELP Run the e2e tests.
eval $$($(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION)) && go test -tags $(GO_BUILD_TAGS) -v ./test/e2e/...
go test -tags $(GO_BUILD_TAGS) -v ./test/e2e/...

export REG_PKG_NAME=registry-operator
export PLAIN_PKG_NAME=plain-operator
export CATALOG_IMG=${E2E_REGISTRY_NAME}.${E2E_REGISTRY_NAMESPACE}.svc:5000/test-catalog:e2e
.PHONY: test-ext-dev-e2e
test-ext-dev-e2e: $(SETUP_ENVTEST) $(OPERATOR_SDK) $(KUSTOMIZE) $(KIND) #HELP Run extension create, upgrade and delete tests.
test/extension-developer-e2e/setup.sh $(OPERATOR_SDK) $(CONTAINER_RUNTIME) $(KUSTOMIZE) $(KIND) $(KIND_CLUSTER_NAME) ${E2E_REGISTRY_NAMESPACE}
eval $$($(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION)) && go test -tags $(GO_BUILD_TAGS) -v ./test/extension-developer-e2e/...
go test -tags $(GO_BUILD_TAGS) -v ./test/extension-developer-e2e/...

.PHONY: test-unit
ENVTEST_VERSION = $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.x/')
Expand Down Expand Up @@ -153,7 +151,19 @@ e2e-coverage:

.PHONY: kind-load
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the .PHONY target annotation here? We don't generate a versioned artifact as a result of this make target.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh, I just blew up this PR with an ill-advised force push. For a small change like this I'm going to start over.

kind-load: $(KIND) #EXHELP Loads the currently constructed image onto the cluster.
ifeq ($(CONTAINER_RUNTIME),podman)
@echo "Using Podman"
@DEPLOY_TEMPLATE_IMG_NAME=quay.io/operator-framework/operator-controller:devel; \
TMP_FILE=temp_image.tar; \
podman tag $(IMG) $$DEPLOY_TEMPLATE_IMG_NAME; \
echo "Saving image to temporary file $$TMP_FILE"; \
podman save $$DEPLOY_TEMPLATE_IMG_NAME -o $$TMP_FILE; \
$(KIND) load image-archive $$TMP_FILE --name $(KIND_CLUSTER_NAME); \
rm $$TMP_FILE
else
@echo "Using Docker"
$(KIND) load docker-image $(IMG) --name $(KIND_CLUSTER_NAME)
endif

kind-deploy: export MANIFEST="./operator-controller.yaml"
kind-deploy: manifests $(KUSTOMIZE) #EXHELP Install controller and dependencies onto the kind cluster.
Expand All @@ -163,7 +173,8 @@ kind-deploy: manifests $(KUSTOMIZE) #EXHELP Install controller and dependencies
.PHONY: kind-cluster
kind-cluster: $(KIND) #EXHELP Standup a kind cluster.
-$(KIND) delete cluster --name ${KIND_CLUSTER_NAME}
$(KIND) create cluster --name ${KIND_CLUSTER_NAME} --image ${KIND_CLUSTER_IMAGE}
# kind-config.yaml can be deleted after upgrading to Kubernetes 1.30
$(KIND) create cluster --name ${KIND_CLUSTER_NAME} --image ${KIND_CLUSTER_IMAGE} --config ./kind-config.yaml
$(KIND) export kubeconfig --name ${KIND_CLUSTER_NAME}

.PHONY: kind-clean
Expand Down Expand Up @@ -216,7 +227,7 @@ run: docker-build kind-cluster kind-load kind-deploy #HELP Build the operator-co

.PHONY: docker-build
docker-build: build-linux #EXHELP Build docker image for operator-controller with GOOS=linux and local GOARCH.
docker build -t ${IMG} -f Dockerfile ./bin/linux
$(CONTAINER_RUNTIME) build -t ${IMG} -f Dockerfile ./bin/linux

#SECTION Release

Expand Down
24 changes: 22 additions & 2 deletions api/v1alpha1/clusterextension_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import (
"github.com/operator-framework/operator-controller/internal/conditionsets"
)

var (
ClusterExtensionGVK = SchemeBuilder.GroupVersion.WithKind("ClusterExtension")
ClusterExtensionKind = ClusterExtensionGVK.Kind
)

type UpgradeConstraintPolicy string

const (
Expand Down Expand Up @@ -75,15 +80,20 @@ type ClusterExtensionSpec struct {

const (
// TODO(user): add more Types, here and into init()
TypeInstalled = "Installed"
TypeResolved = "Resolved"
TypeInstalled = "Installed"
TypeResolved = "Resolved"
TypeHasValidBundle = "HasValidBundle"
TypeHealthy = "Healthy"

// TypeDeprecated is a rollup condition that is present when
// any of the deprecated conditions are present.
TypeDeprecated = "Deprecated"
TypePackageDeprecated = "PackageDeprecated"
TypeChannelDeprecated = "ChannelDeprecated"
TypeBundleDeprecated = "BundleDeprecated"

ReasonErrorGettingClient = "ErrorGettingClient"
ReasonBundleLoadFailed = "BundleLoadFailed"
ReasonBundleLookupFailed = "BundleLookupFailed"
ReasonInstallationFailed = "InstallationFailed"
ReasonInstallationStatusUnknown = "InstallationStatusUnknown"
Expand All @@ -93,13 +103,18 @@ const (
ReasonResolutionUnknown = "ResolutionUnknown"
ReasonSuccess = "Success"
ReasonDeprecated = "Deprecated"
ReasonErrorGettingReleaseState = "ErrorGettingReleaseState"
ReasonUpgradeFailed = "UpgradeFailed"
ReasonCreateDynamicWatchFailed = "CreateDynamicWatchFailed"
)

func init() {
// TODO(user): add Types from above
conditionsets.ConditionTypes = append(conditionsets.ConditionTypes,
TypeInstalled,
TypeResolved,
TypeHasValidBundle,
TypeHealthy,
TypeDeprecated,
TypePackageDeprecated,
TypeChannelDeprecated,
Expand All @@ -116,6 +131,11 @@ func init() {
ReasonInvalidSpec,
ReasonSuccess,
ReasonDeprecated,
ReasonErrorGettingReleaseState,
ReasonUpgradeFailed,
ReasonCreateDynamicWatchFailed,
ReasonBundleLoadFailed,
ReasonErrorGettingClient,
)
}

Expand Down
82 changes: 64 additions & 18 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ package main

import (
"flag"
"fmt"
"net/http"
"net/url"
"os"
"time"

Expand All @@ -35,13 +37,17 @@ import (
"sigs.k8s.io/controller-runtime/pkg/metrics/server"

catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
"github.com/operator-framework/deppy/pkg/deppy/solver"
helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client"
rukpakv1alpha2 "github.com/operator-framework/rukpak/api/v1alpha2"

ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
"github.com/operator-framework/operator-controller/internal/catalogmetadata/cache"
catalogclient "github.com/operator-framework/operator-controller/internal/catalogmetadata/client"
"github.com/operator-framework/operator-controller/internal/controllers"
"github.com/operator-framework/operator-controller/internal/rukpak/handler"
"github.com/operator-framework/operator-controller/internal/rukpak/source"
"github.com/operator-framework/operator-controller/internal/rukpak/storage"
"github.com/operator-framework/operator-controller/internal/rukpak/util"
"github.com/operator-framework/operator-controller/pkg/features"
)

Expand All @@ -63,17 +69,25 @@ func init() {

func main() {
var (
metricsAddr string
enableLeaderElection bool
probeAddr string
cachePath string
metricsAddr string
enableLeaderElection bool
probeAddr string
cachePath string
httpExternalAddr string
systemNamespace string
unpackImage string
provisionerStorageDirectory string
)
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.StringVar(&httpExternalAddr, "http-external-address", "http://localhost:8080", "The external address at which the http server is reachable.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.StringVar(&cachePath, "cache-path", "/var/cache", "The local directory path used for filesystem based caching")
flag.StringVar(&systemNamespace, "system-namespace", "", "Configures the namespace that gets used to deploy system resources.")
flag.StringVar(&unpackImage, "unpack-image", util.DefaultUnpackImage, "Configures the container image that gets used to unpack Bundle contents.")
flag.StringVar(&provisionerStorageDirectory, "provisioner-storage-dir", storage.DefaultBundleCacheDir, "The directory that is used to store bundle contents.")
opts := zap.Options{
Development: true,
}
Expand All @@ -85,6 +99,7 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts), zap.StacktraceLevel(zapcore.DPanicLevel)))

fmt.Println("set up manager")
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Metrics: server.Options{BindAddress: metricsAddr},
Expand All @@ -111,29 +126,60 @@ func main() {
cl := mgr.GetClient()
catalogClient := catalogclient.New(cl, cache.NewFilesystemCache(cachePath, &http.Client{Timeout: 10 * time.Second}))

resolver, err := solver.New()
cfgGetter, err := helmclient.NewActionConfigGetter(mgr.GetConfig(), mgr.GetRESTMapper(), mgr.GetLogger())
if err != nil {
setupLog.Error(err, "unable to create a solver")
setupLog.Error(err, "unable to config for creating helm client")
os.Exit(1)
}

if err = (&controllers.ClusterExtensionReconciler{
Client: cl,
BundleProvider: catalogClient,
Scheme: mgr.GetScheme(),
Resolver: resolver,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ClusterExtension")
acg, err := helmclient.NewActionClientGetter(cfgGetter)
if err != nil {
setupLog.Error(err, "unable to create helm client")
os.Exit(1)
}

if systemNamespace == "" {
systemNamespace = util.PodNamespace()
}

unpacker, err := source.NewDefaultUnpacker(mgr, systemNamespace, unpackImage)
if err != nil {
setupLog.Error(err, "unable to create unpacker")
os.Exit(1)
}

if err = (&controllers.ExtensionReconciler{
Client: cl,
BundleProvider: catalogClient,
storageURL, err := url.Parse(fmt.Sprintf("%s/bundles/", httpExternalAddr))
if err != nil {
setupLog.Error(err, "unable to parse bundle content server URL")
os.Exit(1)
}

localStorage := &storage.LocalDirectory{
RootDirectory: provisionerStorageDirectory,
URL: *storageURL,
}

if err = (&controllers.ClusterExtensionReconciler{
Client: cl,
ReleaseNamespace: systemNamespace,
BundleProvider: catalogClient,
Scheme: mgr.GetScheme(),
ActionClientGetter: acg,
Unpacker: unpacker,
Storage: localStorage,
Handler: handler.HandlerFunc(handler.HandleClusterExtension),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Extension")
setupLog.Error(err, "unable to create controller", "controller", "ClusterExtension")
os.Exit(1)
}

// if err = (&controllers.ExtensionReconciler{
// Client: cl,
// BundleProvider: catalogClient,
// }).SetupWithManager(mgr); err != nil {
// setupLog.Error(err, "unable to create controller", "controller", "Extension")
// os.Exit(1)
// }
//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ spec:
volumeMounts:
- name: cache
mountPath: /var/cache
- name: bundle-cache
mountPath: /var/cache/bundles
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down Expand Up @@ -109,3 +111,5 @@ spec:
volumes:
- name: cache
emptyDir: {}
- name: bundle-cache
emptyDir: {}
27 changes: 22 additions & 5 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ kind: ClusterRole
metadata:
name: manager-role
rules:
- apiGroups:
- '*'
resources:
- '*'
verbs:
- '*'
- apiGroups:
- catalogd.operatorframework.io
resources:
Expand All @@ -19,16 +25,27 @@ rules:
- list
- watch
- apiGroups:
- core.rukpak.io
- ""
resources:
- configmaps
verbs:
- list
- watch
- apiGroups:
- ""
resources:
- bundledeployments
- pods
verbs:
- create
- get
- delete
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
- pods/log
verbs:
- get
- apiGroups:
- kappctrl.k14s.io
resources:
Expand Down
Loading