Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ require (
github.com/google/go-containerregistry v0.20.6
github.com/google/trillian v1.7.2
github.com/google/uuid v1.6.0
github.com/onsi/ginkgo/v2 v2.23.4
github.com/onsi/gomega v1.37.0
github.com/onsi/ginkgo/v2 v2.25.1
github.com/onsi/gomega v1.38.2
github.com/openshift/api v0.0.0-20251023193535-8691c3014652
github.com/operator-framework/api v0.35.0
github.com/operator-framework/operator-lib v0.19.0
Expand All @@ -30,11 +30,12 @@ require (
)

require (
github.com/Masterminds/semver/v3 v3.4.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.18.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/docker/cli v28.2.2+incompatible // indirect
github.com/docker/cli v28.3.3+incompatible // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker-credential-helpers v0.9.4 // indirect
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
Expand Down Expand Up @@ -95,7 +96,6 @@ require (
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.34.1 // indirect
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
Expand Down
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0=
github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand All @@ -12,8 +14,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/cli v28.2.2+incompatible h1:qzx5BNUDFqlvyq4AHzdNB7gSyVTmU4cgsyN9SdInc1A=
github.com/docker/cli v28.2.2+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/cli v28.3.3+incompatible h1:fp9ZHAr1WWPGdIWBM1b3zLtgCF+83gRdVMTJsUeiyAo=
github.com/docker/cli v28.3.3+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker-credential-helpers v0.9.4 h1:76ItO69/AP/V4yT9V4uuuItG0B1N8hvt0T0c0NN/DzI=
Expand Down Expand Up @@ -113,10 +115,10 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/onsi/ginkgo/v2 v2.23.4 h1:ktYTpKJAVZnDT4VjxSbiBenUjmlL/5QkBEocaWXiQus=
github.com/onsi/ginkgo/v2 v2.23.4/go.mod h1:Bt66ApGPBFzHyR+JO10Zbt0Gsp4uWxu5mIOTusL46e8=
github.com/onsi/gomega v1.37.0 h1:CdEG8g0S133B4OswTDC/5XPSzE1OeP29QOioj2PID2Y=
github.com/onsi/gomega v1.37.0/go.mod h1:8D9+Txp43QWKhM24yyOBEdpkzN8FvJyAwecBgsU4KU0=
github.com/onsi/ginkgo/v2 v2.25.1 h1:Fwp6crTREKM+oA6Cz4MsO8RhKQzs2/gOIVOUscMAfZY=
github.com/onsi/ginkgo/v2 v2.25.1/go.mod h1:ppTWQ1dh9KM/F1XgpeRqelR+zHVwV81DGRSDnFxK7Sk=
github.com/onsi/gomega v1.38.2 h1:eZCjf2xjZAqe+LeWvKb5weQ+NcPwX84kqJ0cZNxok2A=
github.com/onsi/gomega v1.38.2/go.mod h1:W2MJcYxRGV63b418Ai34Ud0hEdTVXq9NW9+Sx6uXf3k=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=
Expand Down
4 changes: 0 additions & 4 deletions test/e2e/support/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import (
"github.com/onsi/ginkgo/v2"
"github.com/onsi/ginkgo/v2/dsl/core"
. "github.com/onsi/gomega"
olm "github.com/operator-framework/api/pkg/operators/v1"
olmAlpha "github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/securesign/operator/api/v1alpha1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -52,8 +50,6 @@ func CreateClient() (client.Client, error) {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(v1alpha1.AddToScheme(scheme))
utilruntime.Must(routev1.AddToScheme(scheme))
utilruntime.Must(olmAlpha.AddToScheme(scheme))
utilruntime.Must(olm.AddToScheme(scheme))

cfg, err := config.GetConfig()
if err != nil {
Expand Down
134 changes: 134 additions & 0 deletions test/e2e/support/kubernetes/olm/olm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package olm

import (
"context"
"fmt"
"strconv"
"strings"

olm "github.com/operator-framework/api/pkg/operators/v1"
"github.com/operator-framework/api/pkg/operators/v1alpha1"
coreV1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// olm types
type subscriptionExtension struct {
v1alpha1.Subscription
}

func (e *subscriptionExtension) Unwrap() client.Object {
return &e.Subscription
}

func (e *subscriptionExtension) IsReady(ctx context.Context, cli client.Client) bool {
s := e.getInstalledCSV(ctx, cli)
return s != nil
}

func (e *subscriptionExtension) GetVersion(ctx context.Context, cli client.Client) string {
s := e.getInstalledCSV(ctx, cli)
if s == nil {
return ""
}
return s.Spec.Version.String()

}

func (e *subscriptionExtension) getInstalledCSV(ctx context.Context, cli client.Client) *v1alpha1.ClusterServiceVersion {
lst := v1alpha1.ClusterServiceVersionList{}
if err := cli.List(ctx, &lst, client.InNamespace(e.Namespace)); err != nil {
return nil
}
for _, s := range lst.Items {
if strings.Contains(s.Name, e.Name) && s.Status.Phase == v1alpha1.CSVPhaseSucceeded {
return &s

}
}
return nil
}

type catalogSourceWrapper struct {
v1alpha1.CatalogSource
}

func (c *catalogSourceWrapper) Unwrap() client.Object {
return &c.CatalogSource
}

func (c *catalogSourceWrapper) IsReady(ctx context.Context, cli client.Client) bool {
if c.Status.GRPCConnectionState == nil {
return false
}
return c.Status.GRPCConnectionState.LastObservedState == "READY"
}

func (c *catalogSourceWrapper) UpdateSourceImage(s string) {
c.Spec.Image = s
}

func OlmInstaller(ctx context.Context, cli client.Client, catalogImage, ns, packageName, channel string, ocp bool) (Extension, ExtensionSource, error) {
scheme := cli.Scheme()
utilruntime.Must(v1alpha1.AddToScheme(scheme))
utilruntime.Must(olm.AddToScheme(scheme))

og := &olm.OperatorGroup{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
Name: packageName,
},
Spec: olm.OperatorGroupSpec{
TargetNamespaces: []string{},
},
}

catalog := &catalogSourceWrapper{

v1alpha1.CatalogSource{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
Name: fmt.Sprintf("%s-catalog", packageName),
},
Spec: v1alpha1.CatalogSourceSpec{
Image: catalogImage,
SourceType: "grpc",
DisplayName: "OLM upgrade test Catalog",
Publisher: "grpc",
},
},
}

subscription := &subscriptionExtension{
v1alpha1.Subscription{
ObjectMeta: metav1.ObjectMeta{
Name: packageName,
Namespace: ns,
},
Spec: &v1alpha1.SubscriptionSpec{
CatalogSource: catalog.Name,
CatalogSourceNamespace: catalog.Namespace,
Package: packageName,
Channel: channel,
Config: &v1alpha1.SubscriptionConfig{
Env: []coreV1.EnvVar{
{
Name: "OPENSHIFT",
Value: strconv.FormatBool(ocp),
},
},
},
},
},
}

for _, obj := range []client.Object{catalog.Unwrap(), subscription.Unwrap(), og} {
if err := cli.Create(ctx, obj); client.IgnoreAlreadyExists(err) != nil {
return nil, nil, err
}
}

return subscription, catalog, nil
}
21 changes: 21 additions & 0 deletions test/e2e/support/kubernetes/olm/olm_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package olm

import (
"context"

"sigs.k8s.io/controller-runtime/pkg/client"
)

type ExtensionSource interface {
client.Object
IsReady(context.Context, client.Client) bool
UpdateSourceImage(string)
Unwrap() client.Object
}

type Extension interface {
client.Object
IsReady(context.Context, client.Client) bool
GetVersion(context.Context, client.Client) string
Unwrap() client.Object
}
143 changes: 143 additions & 0 deletions test/e2e/support/kubernetes/olm/olm_v1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package olm

import (
"context"
"fmt"

coreV1 "k8s.io/api/core/v1"
rbacV1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/util/json"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type clusterExtensionWrapper struct {
*unstructured.Unstructured
}

func (e *clusterExtensionWrapper) Unwrap() client.Object {
return e.Unstructured
}

func (e *clusterExtensionWrapper) IsReady(_ context.Context, _ client.Client) bool {
return meta.IsStatusConditionTrue(conditions(e.Object), "Installed")
}

func (e *clusterExtensionWrapper) GetVersion(_ context.Context, _ client.Client) string {
version, _, _ := unstructured.NestedString(e.Object, "status", "install", "bundle", "version")
return version
}

type clusterCatalogSource struct {
*unstructured.Unstructured
}

func (c *clusterCatalogSource) Unwrap() client.Object {
return c.Unstructured
}

func (c *clusterCatalogSource) IsReady(_ context.Context, _ client.Client) bool {
return meta.IsStatusConditionTrue(conditions(c.Object), "Serving")
}

func (c *clusterCatalogSource) UpdateSourceImage(s string) {
_ = unstructured.SetNestedField(c.Object, s, "spec", "source", "image", "ref")
}

func OlmV1Installer(ctx context.Context, cli client.Client, catalogImage, ns, packageName string) (Extension, ExtensionSource, error) {
sa := &coreV1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-installer", packageName),
Namespace: ns,
},
}

crb := &rbacV1.ClusterRoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-installer-%s", packageName, ns),
},
RoleRef: rbacV1.RoleRef{
APIGroup: coreV1.SchemeGroupVersion.Group,
Kind: "ClusterRole",
Name: "cluster-admin",
},
Subjects: []rbacV1.Subject{{Kind: "ServiceAccount", Name: sa.Name, Namespace: ns}},
}

selector := map[string]string{"catalog": "test"}

cs := &clusterCatalogSource{
Unstructured: &unstructured.Unstructured{},
}
cs.SetKind("ClusterCatalog")
cs.SetAPIVersion("olm.operatorframework.io/v1")
cs.SetName(fmt.Sprintf("%s-catalog", packageName))
cs.SetLabels(selector)
if err := unstructured.SetNestedMap(cs.Object, map[string]interface{}{
"availabilityMode": "Available",
"priority": int64(-300),
"source": map[string]interface{}{
"type": "Image",
"image": map[string]interface{}{
"ref": catalogImage,
},
},
}, "spec"); err != nil {
return nil, nil, err
}

es := &clusterExtensionWrapper{
Unstructured: &unstructured.Unstructured{},
}
es.SetKind("ClusterExtension")
es.SetAPIVersion("olm.operatorframework.io/v1")
es.SetName(packageName)

if err := unstructured.SetNestedMap(es.Object, map[string]interface{}{
"namespace": ns,
"serviceAccount": map[string]interface{}{"name": sa.Name},
"source": map[string]interface{}{
"sourceType": "Catalog",
"catalog": map[string]interface{}{
"packageName": packageName,
},
},
}, "spec"); err != nil {
return nil, nil, err
}
if err := unstructured.SetNestedStringMap(cs.Object, selector, "spec", "source", "catalog", "selector", "matchLabels"); err != nil {
return nil, nil, err
}

for _, obj := range []client.Object{sa, crb, es.Unwrap(), cs.Unwrap()} {
if err := cli.Create(ctx, obj); err != nil {
return nil, nil, err
}
}

return es, cs, nil
}

func conditions(object map[string]interface{}) []metav1.Condition {
var (
conditionsSlice []interface{}
found bool
err error
)
if conditionsSlice, found, err = unstructured.NestedSlice(object, "status", "conditions"); !found || err != nil {
return nil
}

jsonBytes, err := json.Marshal(conditionsSlice)
if err != nil {
return nil
}

var typedConditions []metav1.Condition
if err := json.Unmarshal(jsonBytes, &typedConditions); err != nil {
return nil
}
return typedConditions
}
Loading
Loading