Skip to content

Commit

Permalink
registry+v1: support webhooks, add simple converter CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
joelanford committed Dec 5, 2024
1 parent e51c0c2 commit ae93540
Show file tree
Hide file tree
Showing 18 changed files with 2,519 additions and 882 deletions.
31 changes: 22 additions & 9 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import (
"github.com/operator-framework/operator-controller/internal/finalizers"
"github.com/operator-framework/operator-controller/internal/httputil"
"github.com/operator-framework/operator-controller/internal/resolve"
"github.com/operator-framework/operator-controller/internal/rukpak/convert"
"github.com/operator-framework/operator-controller/internal/rukpak/preflights/crdupgradesafety"
"github.com/operator-framework/operator-controller/internal/rukpak/source"
"github.com/operator-framework/operator-controller/internal/scheme"
Expand Down Expand Up @@ -88,14 +89,15 @@ func podNamespace() string {

func main() {
var (
metricsAddr string
enableLeaderElection bool
probeAddr string
cachePath string
operatorControllerVersion bool
systemNamespace string
caCertDir string
globalPullSecret string
metricsAddr string
enableLeaderElection bool
probeAddr string
cachePath string
operatorControllerVersion bool
systemNamespace string
caCertDir string
globalPullSecret string
registryV1CertProviderName 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.")
Expand All @@ -108,10 +110,14 @@ func main() {
flag.StringVar(&systemNamespace, "system-namespace", "", "Configures the namespace that gets used to deploy system resources.")
flag.StringVar(&globalPullSecret, "global-pull-secret", "", "The <namespace>/<name> of the global pull secret that is going to be used to pull bundle images.")

features.InitializeFromCLIFlags(pflag.CommandLine)
if features.OperatorControllerFeatureGate.Enabled(features.RegistryV1WebhookSupport) {
flag.StringVar(&registryV1CertProviderName, "registry-v1-cert-provider", "", "Certificate provider to use for registry+v1 webhook certificates")
}

klog.InitFlags(flag.CommandLine)

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

if operatorControllerVersion {
Expand Down Expand Up @@ -284,9 +290,16 @@ func main() {
crdupgradesafety.NewPreflight(aeClient.CustomResourceDefinitions()),
}

rv1CertProvider, err := convert.CertProviderByName(registryV1CertProviderName)
if err != nil {
setupLog.Error(err, "failed to load certificate provider")
os.Exit(1)
}

applier := &applier.Helm{
ActionClientGetter: acg,
Preflights: preflights,
ConvertToChartOpts: []convert.ToHelmChartOption{convert.WithCertificateProvider(rv1CertProvider)},
}

cm := contentmanager.NewManager(clientRestConfigMapper, mgr.GetConfig(), mgr.GetRESTMapper())
Expand Down
72 changes: 72 additions & 0 deletions cmd/registryv1-to-helm/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package main

import (
"fmt"
"os"
"path/filepath"

"github.com/spf13/cobra"
"helm.sh/helm/v3/pkg/chartutil"

"github.com/operator-framework/operator-controller/internal/features"
"github.com/operator-framework/operator-controller/internal/rukpak/convert"
)

func main() {
if err := rootCmd().Execute(); err != nil {
os.Exit(1)
}
}

func rootCmd() *cobra.Command {
var registryV1CertProviderName string
cmd := &cobra.Command{
Use: "registryv1-to-helm <registry+v1-directory-path> [output-path]",
Args: cobra.RangeArgs(1, 2),
Run: func(cmd *cobra.Command, args []string) {
registryv1Path := args[0]

saveDir := "."
if len(args) == 2 {
saveDir = args[1]
}

rv1, err := convert.LoadRegistryV1(cmd.Context(), os.DirFS(registryv1Path))
if err != nil {
fmt.Fprintf(os.Stderr, "failed to load registry+v1 bundle: %v\n", err)
os.Exit(1)
}

rv1CertProvider, err := convert.CertProviderByName(registryV1CertProviderName)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to load certificate provider: %v\n", err)
os.Exit(1)
}

chrt, err := rv1.ToHelmChart(convert.WithCertificateProvider(rv1CertProvider))
if err != nil {
fmt.Fprintf(os.Stderr, "failed to convert registry v1 to helm chart: %v\n", err)
os.Exit(1)
}

if err := chartutil.SaveDir(chrt, saveDir); err != nil {
fmt.Fprintf(os.Stderr, "failed to write helm chart to directory: %v\n", err)
os.Exit(1)
}

origChartDir := filepath.Join(saveDir, chrt.Metadata.Name)
desiredChartDir := filepath.Join(saveDir, fmt.Sprintf("%s-%s", chrt.Metadata.Name, chrt.Metadata.Version))
if err := os.Rename(origChartDir, desiredChartDir); err != nil {
fmt.Fprintf(os.Stderr, "failed to rename helm chart directory: %v\n", err)
os.Exit(1)
}
cmd.Printf("Chart saved to %s\n", desiredChartDir)
},
}
features.InitializeFromCLIFlags(cmd.Flags())
if features.OperatorControllerFeatureGate.Enabled(features.RegistryV1WebhookSupport) {
cmd.Flags().StringVar(&registryV1CertProviderName, "registry-v1-cert-provider", "", "a certificate provider to use to generate certificates for registry+v1-defined webhooks (if unset, registry+v1 bundles that define webhooks are unsupported)")
}

return cmd
}
39 changes: 39 additions & 0 deletions cmd/registryv1-to-helm/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node-role.kubernetes.io/master
operator: Exists
nodeSelector:
overrideKey1: overrideValue1

selector:
overrideKey2: overrideValue2

tolerations:
- effect: NoSchedule
key: node-role.kubernetes.io/master2

volumes:
- name: argocd-operator-token-5z5z2
emptyDir: {}

env:
- name: WATCH_NAMESPACE
value: BAR

envFrom:
- configMapRef:
name: my-configmap
- secretRef:
name: my-secret

resources:
requests:
cpu: 100m
memory: 100Mi

volumeMounts:
- name: tmp
mountPath: override
40 changes: 12 additions & 28 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ require (
github.com/BurntSushi/toml v1.4.0
github.com/Masterminds/semver/v3 v3.3.1
github.com/blang/semver/v4 v4.0.0
github.com/cert-manager/cert-manager v1.16.1
github.com/containerd/containerd v1.7.24
github.com/containers/image/v5 v5.32.2
github.com/fsnotify/fsnotify v1.8.0
github.com/go-logr/logr v1.4.2
github.com/go-openapi/spec v0.21.0
github.com/google/go-cmp v0.6.0
github.com/google/go-containerregistry v0.20.2
github.com/opencontainers/go-digest v1.0.0
github.com/operator-framework/api v0.27.0
github.com/operator-framework/catalogd v1.0.0
github.com/operator-framework/helm-operator-plugins v0.7.0
github.com/operator-framework/operator-registry v1.48.0
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.10.0
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
Expand All @@ -30,7 +33,7 @@ require (
k8s.io/client-go v0.31.3
k8s.io/component-base v0.31.2
k8s.io/klog/v2 v2.130.1
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
k8s.io/utils v0.0.0-20240921022957-49e7df575cb6
sigs.k8s.io/controller-runtime v0.19.0
sigs.k8s.io/yaml v1.4.0
)
Expand All @@ -48,22 +51,16 @@ require (
github.com/Microsoft/hcsshim v0.12.5 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/containerd/cgroups/v3 v3.0.3 // indirect
github.com/containerd/containerd/api v1.7.19 // indirect
github.com/containerd/continuity v0.4.2 // indirect
github.com/containerd/errdefs v0.3.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.15.1 // indirect
github.com/containerd/ttrpc v1.2.5 // indirect
github.com/containerd/typeurl/v2 v2.1.1 // indirect
github.com/containers/common v0.60.4 // indirect
github.com/containers/libtrust v0.0.0-20230121012942-c1716e8a8d01 // indirect
github.com/containers/ocicrypt v1.2.0 // indirect
github.com/containers/storage v1.55.0 // indirect
Expand All @@ -81,11 +78,11 @@ require (
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emicklei/go-restful/v3 v3.11.2 // indirect
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
Expand All @@ -101,7 +98,6 @@ require (
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/loads v0.22.0 // indirect
github.com/go-openapi/runtime v0.28.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/strfmt v0.23.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-openapi/validate v0.24.0 // indirect
Expand All @@ -110,16 +106,14 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/cel-go v0.20.1 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/gosuri/uitable v0.0.4 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/h2non/filetype v1.1.3 // indirect
github.com/h2non/go-is-svg v0.0.0-20160927212452-35e8c4b0612c // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
Expand Down Expand Up @@ -172,7 +166,6 @@ require (
github.com/opencontainers/runtime-spec v1.2.0 // indirect
github.com/openshift/crd-schema-checker v0.0.0-20240404194209-35a9033b1d11 // indirect
github.com/operator-framework/operator-lib v0.15.0 // indirect
github.com/otiai10/copy v1.14.0 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand All @@ -191,9 +184,7 @@ require (
github.com/sigstore/sigstore v1.8.4 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/stefanberger/go-pkcs11uri v0.0.0-20230803200340-78284954bff6 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
github.com/titanous/rocacheck v0.0.0-20171023193734-afe73141d399 // indirect
Expand All @@ -207,42 +198,35 @@ require (
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.etcd.io/bbolt v1.3.11 // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect
go.mozilla.org/pkcs7 v0.0.0-20210826202110-33d05740a352 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.starlark.net v0.0.0-20230612165344-9532f5667272 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/oauth2 v0.23.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/time v0.6.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiserver v0.31.2 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/kube-openapi v0.0.0-20240903163716-9e1beecbcb38 // indirect
k8s.io/kubectl v0.31.1 // indirect
oras.land/oras-go v1.2.5 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 // indirect
sigs.k8s.io/gateway-api v1.1.0 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.17.2 // indirect
sigs.k8s.io/kustomize/kyaml v0.17.1 // indirect
Expand Down
Loading

0 comments on commit ae93540

Please sign in to comment.