Skip to content

Commit

Permalink
use the most recent rukpak unpacker changes
Browse files Browse the repository at this point in the history
Signed-off-by: Bryce Palmer <bpalmer@redhat.com>
  • Loading branch information
everettraven committed Jun 15, 2023
1 parent dd3ad22 commit d8727d2
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 64 deletions.
17 changes: 14 additions & 3 deletions api/core/v1alpha1/catalog_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,27 @@ type CatalogList struct {
type CatalogSpec struct {
// 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
Source source.BundleSource `json:"source"`
Source CatalogSource `json:"source"`
}

// CatalogSource contains the sourcing information for a Catalog
type CatalogSource struct {
// Type defines the source type for this catalog.
Type source.SourceType `json:"type"`

Image *source.ImageSource `json:"image,omitempty"`
Git *source.GitSource `json:"git,omitempty"`
ConfigMaps []source.ConfigMapSource `json:"configMaps,omitempty"`
HTTP *source.HTTPSource `json:"http,omitempty"`
}

// CatalogStatus defines the observed state of Catalog
type CatalogStatus struct {
// Conditions store the status conditions of the Catalog instances
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`

ResolvedSource *source.BundleSource `json:"resolvedSource,omitempty"`
Phase string `json:"phase,omitempty"`
ResolvedSource *source.Source `json:"resolvedSource,omitempty"`
Phase string `json:"phase,omitempty"`
}

func init() {
Expand Down
39 changes: 38 additions & 1 deletion api/core/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 24 additions & 25 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ limitations under the License.
package main

import (
"crypto/x509"
"flag"
"fmt"
"os"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth"

"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -106,35 +106,34 @@ func main() {
os.Exit(1)
}

unpackerOpts := source.DefaultUnpackerOptions{
Cluster: mgr,
RootCAs: &x509.CertPool{},
ImageUnpackerOptions: []source.ImageUnpackerOption{
source.WithBundleDir("/configs"),
source.WithFieldManager("catalogd-core"),
kubeClient, err := kubernetes.NewForConfig(mgr.GetConfig())
if err != nil {
setupLog.Error(err, "unable to setup kube client")
os.Exit(1)
}

unpacker := source.NewUnpacker(map[source.SourceType]source.Unpacker{
source.SourceTypeImage: source.NewImageUnpacker(
mgr.GetClient(),
kubeClient,
source.WithPodNamespace(sysNs),
source.WithFieldManager("catalogd-core"),
source.WithUnpackImage(unpackImage),
},
GitUnpackerOptions: []source.GitUnpackerOption{
source.WithDir("/configs"),
),
source.SourceTypeGit: source.NewGitUnpacker(
mgr.GetClient(),
source.WithGitSecretNamespace(sysNs),
},
ConfigMapUnpackerOptions: []source.ConfigMapUnpackerOption{
),
source.SourceTypeConfigMaps: source.NewConfigMapUnpacker(
mgr.GetClient(),
source.WithConfigMapNamespace(sysNs),
},
UploadUnpackerOptions: []source.UploadUnpackerOption{
source.WithBaseDownloadURL(""),
source.WithBearerToken(mgr.GetConfig().BearerToken),
},
HTTPUnpackerOptions: []source.HTTPUnpackerOption{
),
source.SourceTypeHTTP: source.NewHTTPUnpacker(
mgr.GetClient(),
source.WithHTTPSecretNamespace(sysNs),
},
}

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

if err = (&corecontrollers.CatalogReconciler{
Client: mgr.GetClient(),
Expand Down
32 changes: 8 additions & 24 deletions config/crd/bases/catalogd.operatorframework.io_catalogs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ spec:
metadata in the FBC format https://olm.operatorframework.io/docs/reference/file-based-catalogs/#docs
properties:
configMaps:
description: ConfigMaps is a list of config map references and
their relative directory paths that represent a bundle filesystem.
items:
properties:
configMap:
Expand All @@ -63,8 +61,6 @@ spec:
type: object
type: array
git:
description: Git is the git repository that backs the content
of this Bundle.
properties:
auth:
description: Auth configures the authorization method if necessary.
Expand Down Expand Up @@ -136,8 +132,6 @@ spec:
- repository
type: object
http:
description: HTTP is the remote location that backs the content
of this Bundle.
properties:
auth:
description: Auth configures the authorization method if necessary.
Expand Down Expand Up @@ -179,8 +173,6 @@ spec:
- url
type: object
image:
description: Image is the bundle image that backs the content
of this bundle.
properties:
pullSecret:
description: ImagePullSecretName contains the name of the
Expand All @@ -195,15 +187,8 @@ spec:
- ref
type: object
type:
description: Type defines the kind of Bundle content being sourced.
description: Type defines the source type for this catalog.
type: string
upload:
description: Upload is a source that enables this Bundle's content
to be uploaded via Rukpak's bundle upload service. This source
type is primarily useful with bundle development workflows because
it enables bundle developers to inject a local bundle directly
into the cluster.
type: object
required:
- type
type: object
Expand Down Expand Up @@ -286,11 +271,10 @@ spec:
phase:
type: string
resolvedSource:
description: 'TODO: Rename this. Source?'
properties:
configMaps:
description: ConfigMaps is a list of config map references and
their relative directory paths that represent a bundle filesystem.
their relative directory paths that represent a source filesystem.
items:
properties:
configMap:
Expand All @@ -314,7 +298,7 @@ spec:
type: array
git:
description: Git is the git repository that backs the content
of this Bundle.
of this Source.
properties:
auth:
description: Auth configures the authorization method if necessary.
Expand Down Expand Up @@ -387,7 +371,7 @@ spec:
type: object
http:
description: HTTP is the remote location that backs the content
of this Bundle.
of this Source.
properties:
auth:
description: Auth configures the authorization method if necessary.
Expand Down Expand Up @@ -429,8 +413,8 @@ spec:
- url
type: object
image:
description: Image is the bundle image that backs the content
of this bundle.
description: Image is the image that backs the content of this
Source.
properties:
pullSecret:
description: ImagePullSecretName contains the name of the
Expand All @@ -445,10 +429,10 @@ spec:
- ref
type: object
type:
description: Type defines the kind of Bundle content being sourced.
description: Type defines the kind of Source content being sourced.
type: string
upload:
description: Upload is a source that enables this Bundle's content
description: Upload is a source that enables this Source's content
to be uploaded via Rukpak's bundle upload service. This source
type is primarily useful with bundle development workflows because
it enables bundle developers to inject a local bundle directly
Expand Down
2 changes: 0 additions & 2 deletions config/crd/patches/catalog_validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
- image
- required:
- configMaps
- required:
- upload
- required:
- http

Expand Down
11 changes: 9 additions & 2 deletions pkg/controllers/core/catalog_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,14 @@ func (r *CatalogReconciler) SetupWithManager(mgr ctrl.Manager) error {
}

func (r *CatalogReconciler) reconcile(ctx context.Context, catalog *v1alpha1.Catalog) (ctrl.Result, error) {
unpackResult, err := r.Unpacker.Unpack(ctx, &catalog.Spec.Source, catalog)
src := &source.Source{
Type: catalog.Spec.Source.Type,
Image: catalog.Spec.Source.Image,
Git: catalog.Spec.Source.Git,
ConfigMaps: catalog.Spec.Source.ConfigMaps,
HTTP: catalog.Spec.Source.HTTP,
}
unpackResult, err := r.Unpacker.Unpack(ctx, src, catalog)
if err != nil {
return ctrl.Result{}, updateStatusUnpackFailing(&catalog.Status, fmt.Errorf("source bundle content: %v", err))
}
Expand All @@ -129,7 +136,7 @@ func (r *CatalogReconciler) reconcile(ctx context.Context, catalog *v1alpha1.Cat
// as the already unpacked content. If it does, we should skip this rest
// of the unpacking steps.

fbc, err := declcfg.LoadFS(unpackResult.Bundle)
fbc, err := declcfg.LoadFS(unpackResult.FS)
if err != nil {
return ctrl.Result{}, updateStatusUnpackFailing(&catalog.Status, fmt.Errorf("load FBC from filesystem: %v", err))
}
Expand Down
15 changes: 9 additions & 6 deletions pkg/controllers/core/catalog_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type MockSource struct {
shouldError bool
}

func (ms *MockSource) Unpack(_ context.Context, _ *source.BundleSource, _ client.Object) (*source.Result, error) {
func (ms *MockSource) Unpack(_ context.Context, _ *source.Source, _ client.Object) (*source.Result, error) {
if ms.shouldError {
return nil, errors.New("mocksource error")
}
Expand Down Expand Up @@ -96,7 +96,7 @@ var _ = Describe("Catalogd Controller Test", func() {
catalog = &v1alpha1.Catalog{
ObjectMeta: metav1.ObjectMeta{Name: cKey.Name},
Spec: v1alpha1.CatalogSpec{
Source: source.BundleSource{
Source: v1alpha1.CatalogSource{
Type: "invalid-source",
},
},
Expand Down Expand Up @@ -132,7 +132,7 @@ var _ = Describe("Catalogd Controller Test", func() {
catalog = &v1alpha1.Catalog{
ObjectMeta: metav1.ObjectMeta{Name: cKey.Name},
Spec: v1alpha1.CatalogSpec{
Source: source.BundleSource{
Source: v1alpha1.CatalogSource{
Type: source.SourceTypeImage,
Image: &source.ImageSource{
Ref: "somecatalog:latest",
Expand Down Expand Up @@ -246,9 +246,12 @@ var _ = Describe("Catalogd Controller Test", func() {

mockSource.shouldError = false
mockSource.result = &source.Result{
ResolvedSource: &catalog.Spec.Source,
State: source.StateUnpacked,
Bundle: filesys,
ResolvedSource: &source.Source{
Type: catalog.Spec.Source.Type,
Image: catalog.Spec.Source.Image,
},
State: source.StateUnpacked,
FS: filesys,
}

// reconcile
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/unpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var _ = Describe("Catalog Unpacking", func() {
Name: catalogName,
},
Spec: catalogd.CatalogSpec{
Source: source.BundleSource{
Source: catalogd.CatalogSource{
Type: source.SourceTypeImage,
Image: &source.ImageSource{
Ref: catalogRef,
Expand Down

0 comments on commit d8727d2

Please sign in to comment.