Skip to content
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
4 changes: 4 additions & 0 deletions openshift/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Get the directory where this Makefile is, so we can use it below for including
DIR := $(strip $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))))

GO_BUILD_BINDIR ?=./bin/

include $(addprefix $(DIR)/vendor/github.com/openshift/build-machinery-go/make/, \
targets/openshift/deps.mk \
targets/golang/build.mk \
targets/help.mk \
)

include $(DIR)/.bingo/Variables.mk
Expand Down
125 changes: 125 additions & 0 deletions openshift/cmd/webhook/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package main

import (
"flag"
"os"
"strings"

catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
rukpakv1alpha2 "github.com/operator-framework/rukpak/api/v1alpha2"
"github.com/spf13/pflag"
"go.uber.org/zap/zapcore"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"

carvelv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/kappctrl/v1alpha1"

ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
"github.com/operator-framework/operator-controller/pkg/features"

"github.com/openshift/operator-framework-operator-controller/openshift/pkg/webhook"
)

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
)

func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))

utilruntime.Must(ocv1alpha1.AddToScheme(scheme))
utilruntime.Must(rukpakv1alpha2.AddToScheme(scheme))
utilruntime.Must(catalogd.AddToScheme(scheme))
utilruntime.Must(carvelv1alpha1.AddToScheme(scheme))

//+kubebuilder:scaffold:scheme
}

func main() {
var (
metricsAddr string
enableLeaderElection bool
probeAddr string
allowServiceAccounts commaSeparatedValue
)
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.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.Var(&allowServiceAccounts, "allow-service-account-names", "Comma-separated names of service accounts which are allowed to make create, update and delete Carvel kapp resources.")
opts := zap.Options{
Development: true,
}
opts.BindFlags(flag.CommandLine)

pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
features.OperatorControllerFeatureGate.AddFlag(pflag.CommandLine)
pflag.Parse()

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

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Metrics: server.Options{BindAddress: metricsAddr},
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "9c4404e7.operatorframework.io",
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
// when the Manager ends. This requires the binary to immediately end when the
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
// speeds up voluntary leader transitions as the new leader don't have to wait
// LeaseDuration time first.
//
// In the default scaffold provided, the program ends immediately after
// the manager stops, so would be fine to enable this option. However,
// if you are doing or is intended to do any operation such as perform cleanups
// after the manager stops then its usage might be unsafe.
// LeaderElectionReleaseOnCancel: true,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
}

if err = (&webhook.KAppUserInfo{
WhitelistedUsernames: allowServiceAccounts,
}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "KAppUserInfo")
os.Exit(1)
}
//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
}
if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up ready check")
os.Exit(1)
}

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(1)
}
}

type commaSeparatedValue []string

func (v *commaSeparatedValue) String() string {
return strings.Join(*v, ",")
}

func (v *commaSeparatedValue) Set(value string) error {
*v = strings.Split(value, ",")
return nil
}
9 changes: 1 addition & 8 deletions openshift/generate-manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ set -o pipefail
# Modify these as needed
##################################################

# This is the namespace where all namespace-scoped resources live
NAMESPACE=openshift-operator-controller

# This is a mapping of deployment container names to image placeholder values. For example, given a deployment with
# 2 containers named kube-rbac-proxy and manager, their images will be set to ${KUBE_RBAC_PROXY_IMAGE} and
# ${OPERATOR_CONTROLLER_IMAGE}, respectively. The cluster-olm-operator will replace these placeholders will real image values.
Expand Down Expand Up @@ -39,16 +36,13 @@ trap 'rm -rf $TMP_ROOT' EXIT
TMP_CONFIG="${TMP_ROOT}/config"
cp -a "${REPO_ROOT}/config" "$TMP_CONFIG"

# Override namespace to openshift-operator-controller
$YQ -i ".namespace = \"${NAMESPACE}\"" "${TMP_CONFIG}/default/kustomization.yaml"

# Create a temp dir for manifests
TMP_MANIFEST_DIR="${TMP_ROOT}/manifests"
mkdir -p "$TMP_MANIFEST_DIR"

# Run kustomize, which emits a single yaml file
TMP_KUSTOMIZE_OUTPUT="${TMP_MANIFEST_DIR}/temp.yaml"
$KUSTOMIZE build "${TMP_CONFIG}/default" -o "$TMP_KUSTOMIZE_OUTPUT"
$KUSTOMIZE build "${REPO_ROOT}"/openshift/kustomize/openshift -o "$TMP_KUSTOMIZE_OUTPUT"

for container_name in "${!IMAGE_MAPPINGS[@]}"; do
placeholder="${IMAGE_MAPPINGS[$container_name]}"
Expand Down Expand Up @@ -101,4 +95,3 @@ cp "$TMP_MANIFEST_DIR"/* "$MANIFEST_DIR"/
fi
done
)

79 changes: 76 additions & 3 deletions openshift/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,78 @@
module _
module github.com/openshift/operator-framework-operator-controller/openshift

go 1.20
go 1.21

require github.com/openshift/build-machinery-go v0.0.0-20230306181456-d321ffa04533
toolchain go1.21.0

require (
github.com/openshift/build-machinery-go v0.0.0-20230306181456-d321ffa04533
github.com/operator-framework/catalogd v0.11.0
github.com/operator-framework/operator-controller v0.9.0
github.com/operator-framework/rukpak v0.18.1
github.com/spf13/pflag v1.0.5
github.com/vmware-tanzu/carvel-kapp-controller v0.50.0
go.uber.org/zap v1.27.0
k8s.io/apimachinery v0.29.2
k8s.io/apiserver v0.29.2
k8s.io/client-go v0.29.2
sigs.k8s.io/controller-runtime v0.17.2
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/vmware-tanzu/carvel-vendir v0.36.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.29.2 // indirect
k8s.io/apiextensions-apiserver v0.29.2 // indirect
k8s.io/component-base v0.29.2 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading