Skip to content

Commit

Permalink
(feat): (testing): Add extensible unpacking interface + controller te…
Browse files Browse the repository at this point in the history
…sts (#65)

Signed-off-by: Bryce Palmer <bpalmer@redhat.com>
Signed-off-by: Bryce Palmer <everettraven@gmail.com>
  • Loading branch information
everettraven committed May 24, 2023
1 parent 70ef727 commit 18b182f
Show file tree
Hide file tree
Showing 15 changed files with 1,071 additions and 266 deletions.
18 changes: 13 additions & 5 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

"github.com/operator-framework/catalogd/internal/source"
"github.com/operator-framework/catalogd/internal/version"
"github.com/operator-framework/catalogd/pkg/apis/core/v1beta1"
corecontrollers "github.com/operator-framework/catalogd/pkg/controllers/core"
Expand All @@ -56,16 +57,19 @@ func main() {
metricsAddr string
enableLeaderElection bool
probeAddr string
opmImage string
unpackImage string
profiling bool
catalogdVersion bool
sysNs 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.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.StringVar(&opmImage, "opm-image", "quay.io/operator-framework/opm:v1.26", "The opm image to use when unpacking catalog images")
// TODO: should we move the unpacker to some common place? Or... hear me out... should catalogd just be a rukpak provisioner?
flag.StringVar(&unpackImage, "unpack-image", "quay.io/operator-framework/rukpak:v0.12.0", "The unpack image to use when unpacking catalog images")
flag.StringVar(&sysNs, "system-ns", "catalogd-system", "The namespace catalogd uses for internal state, configuration, and workloads")
opts := zap.Options{
Development: true,
}
Expand Down Expand Up @@ -94,11 +98,15 @@ func main() {
os.Exit(1)
}

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

if err = (&corecontrollers.CatalogReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Cfg: mgr.GetConfig(),
OpmImage: opmImage,
Unpacker: unpacker,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Catalog")
os.Exit(1)
Expand Down
65 changes: 53 additions & 12 deletions config/crd/bases/catalogd.operatorframework.io_catalogs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,33 @@ spec:
spec:
description: CatalogSpec defines the desired state of Catalog
properties:
image:
description: Image is the Catalog image that contains Operators' metadata
in the FBC format https://olm.operatorframework.io/docs/reference/file-based-catalogs/#docs
type: string
pollingInterval:
description: PollingInterval is used to determine the time interval
between checks of the latest index image version. The image is polled
to see if a new version of the image is available. If available,
the latest image is pulled and the cache is updated to contain the
new content.
type: string
source:
description: Source is the source of a Catalog that contains Operators'
metadata in the FBC format https://olm.operatorframework.io/docs/reference/file-based-catalogs/#docs
properties:
image:
description: Image is the catalog image that backs the content
of this catalog.
properties:
pullSecret:
description: PullSecret contains the name of the image pull
secret in the namespace that catalogd is deployed.
type: string
ref:
description: Ref contains the reference to a container image
containing Catalog contents.
type: string
required:
- ref
type: object
type:
description: Type defines the kind of Catalog content being sourced.
type: string
required:
- type
type: object
required:
- image
- source
type: object
status:
description: CatalogStatus defines the observed state of Catalog
Expand Down Expand Up @@ -121,6 +135,33 @@ spec:
- type
type: object
type: array
phase:
type: string
resolvedSource:
description: CatalogSource contains the sourcing information for a
Catalog
properties:
image:
description: Image is the catalog image that backs the content
of this catalog.
properties:
pullSecret:
description: PullSecret contains the name of the image pull
secret in the namespace that catalogd is deployed.
type: string
ref:
description: Ref contains the reference to a container image
containing Catalog contents.
type: string
required:
- ref
type: object
type:
description: Type defines the kind of Catalog content being sourced.
type: string
required:
- type
type: object
type: object
type: object
served: true
Expand Down
8 changes: 8 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ resources:
- bases/catalogd.operatorframework.io_packages.yaml
- bases/catalogd.operatorframework.io_catalogs.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patches:
- path: patches/catalog_validation.yaml
target:
group: apiextensions.k8s.io
version: v1
kind: CustomResourceDefinition
name: catalogs.catalogd.operatorframework.io
6 changes: 6 additions & 0 deletions config/crd/patches/catalog_validation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Union source type
- op: add
path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/source/oneOf
value:
- required:
- image
13 changes: 4 additions & 9 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ kind: ClusterRole
metadata:
name: manager-role
rules:
- apiGroups:
- batch
resources:
- jobs
verbs:
- create
- get
- list
- watch
- apiGroups:
- catalogd.operatorframework.io
resources:
Expand Down Expand Up @@ -96,8 +87,12 @@ rules:
resources:
- pods
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
Expand Down
14 changes: 5 additions & 9 deletions config/samples/core_v1beta1_catalog.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
apiVersion: catalogd.operatorframework.io/v1beta1
kind: Catalog
metadata:
labels:
app.kubernetes.io/name: catalog
app.kubernetes.io/instance: catalog-sample
app.kubernetes.io/part-of: catalogd
app.kuberentes.io/managed-by: kustomize
app.kubernetes.io/created-by: catalogd
name: catalog-sample
name: operatorhubio
spec:
image: quay.io/operatorhubio/catalog:latest
pollingInterval: 45m
source:
type: image
image:
ref: quay.io/operatorhubio/catalog:latest
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ module github.com/operator-framework/catalogd
go 1.19

require (
github.com/nlepage/go-tarfs v1.1.0
github.com/onsi/ginkgo/v2 v2.6.0
github.com/onsi/gomega v1.24.1
github.com/operator-framework/operator-registry v1.26.3
k8s.io/api v0.26.0
k8s.io/apimachinery v0.26.0
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,12 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nlepage/go-tarfs v1.1.0 h1:bsACOiZMB/zFjYG/sE01070i9Fl26MnRpw0L6WuyfVs=
github.com/nlepage/go-tarfs v1.1.0/go.mod h1:IhxRcLhLkawBetnwu/JNuoPkq/6cclAllhgEa6SmzS8=
github.com/onsi/ginkgo/v2 v2.6.0 h1:9t9b9vRUbFq3C4qKFCGkVuq/fIHji802N1nrtkh1mNc=
github.com/onsi/ginkgo/v2 v2.6.0/go.mod h1:63DOGlLAH8+REH8jUGdL3YpCpu7JODesutUjdENfUAc=
github.com/onsi/gomega v1.24.1 h1:KORJXNNTzJXzu4ScJWssJfJMnJ+2QJqhoQSRwNlze9E=
github.com/onsi/gomega v1.24.1/go.mod h1:3AOiACssS3/MajrniINInwbfOOtfZvplPzuRSmvt1jM=
github.com/operator-framework/api v0.17.2-0.20220915200120-ff2dbc53d381 h1:/XHgTzfI0O/RP3I6WF0BiPLVuVkfgVyiw04b0MyCJ2M=
github.com/operator-framework/api v0.17.2-0.20220915200120-ff2dbc53d381/go.mod h1:wof6IrBhVAufc+ZiQo/BB68fKctXiuSEAMbOO29kZdI=
github.com/operator-framework/operator-registry v1.26.3 h1:U+HTGgjAT5RCXU2WkDwa525wcqdo97BsO7WfMhwL5MA=
Expand Down Expand Up @@ -295,6 +299,7 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
Loading

0 comments on commit 18b182f

Please sign in to comment.