Skip to content

Commit ab44850

Browse files
committed
Addressing Gonzalo's comments, use offical Package manifest object
1 parent 233f9b9 commit ab44850

File tree

8 files changed

+106
-83
lines changed

8 files changed

+106
-83
lines changed

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ require (
9595
github.com/gosuri/uitable v0.0.4 // indirect
9696
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
9797
github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0 // indirect
98+
github.com/h2non/filetype v1.1.3 // indirect
99+
github.com/h2non/go-is-svg v0.0.0-20160927212452-35e8c4b0612c // indirect
98100
github.com/hashicorp/errwrap v1.1.0 // indirect
99101
github.com/hashicorp/go-multierror v1.1.1 // indirect
100102
github.com/hashicorp/hcl v1.0.0 // indirect
@@ -128,9 +130,11 @@ require (
128130
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
129131
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
130132
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
133+
github.com/onsi/gomega v1.34.2 // indirect
131134
github.com/opencontainers/go-digest v1.0.0 // indirect
132135
github.com/opencontainers/image-spec v1.1.0 // indirect
133136
github.com/operator-framework/operator-manifest-tools v0.7.0 // indirect
137+
github.com/operator-framework/operator-registry v1.47.0 // indirect
134138
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
135139
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
136140
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect

go.sum

Lines changed: 73 additions & 21 deletions
Large diffs are not rendered by default.

internal/clientsholder/clientsholder.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
cncfNetworkAttachmentv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/client/clientset/versioned/typed/k8s.cni.cncf.io/v1"
3939
apiserverscheme "github.com/openshift/client-go/apiserver/clientset/versioned"
4040
ocpMachine "github.com/openshift/client-go/machineconfiguration/clientset/versioned"
41+
olmpkgclient "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/client/clientset/versioned/typed/operators/v1"
4142
appsv1 "k8s.io/api/apps/v1"
4243
scalingv1 "k8s.io/api/autoscaling/v1"
4344
corev1 "k8s.io/api/core/v1"
@@ -63,6 +64,7 @@ type ClientsHolder struct {
6364
ScalingClient scale.ScalesGetter
6465
APIExtClient apiextv1.Interface
6566
OlmClient olmClient.Interface
67+
OlmPkgClient olmpkgclient.OperatorsV1Interface
6668
OcpClient clientconfigv1.ConfigV1Interface
6769
K8sClient kubernetes.Interface
6870
K8sNetworkingClient networkingv1.NetworkingV1Interface
@@ -287,6 +289,10 @@ func newClientsHolder(filenames ...string) (*ClientsHolder, error) { //nolint:fu
287289
if err != nil {
288290
return nil, fmt.Errorf("cannot instantiate olm clientset: %s", err)
289291
}
292+
clientsHolder.OlmPkgClient, err = olmpkgclient.NewForConfig(clientsHolder.RestConfig)
293+
if err != nil {
294+
return nil, fmt.Errorf("cannot instantiate olm clientset: %s", err)
295+
}
290296
clientsHolder.K8sClient, err = kubernetes.NewForConfig(clientsHolder.RestConfig)
291297
if err != nil {
292298
return nil, fmt.Errorf("cannot instantiate k8sclient: %s", err)

pkg/autodiscover/autodiscover.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
configv1 "github.com/openshift/api/config/v1"
2828
clientconfigv1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
2929
olmv1Alpha "github.com/operator-framework/api/pkg/operators/v1alpha1"
30+
olmPkgv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/operators/v1"
3031
"github.com/redhat-best-practices-for-k8s/certsuite/internal/clientsholder"
3132
"github.com/redhat-best-practices-for-k8s/certsuite/internal/log"
3233
"github.com/redhat-best-practices-for-k8s/certsuite/pkg/compatibility"
@@ -73,7 +74,7 @@ type DiscoveredTestData struct {
7374
AllCsvs []*olmv1Alpha.ClusterServiceVersion
7475
AllInstallPlans []*olmv1Alpha.InstallPlan
7576
AllCatalogSources []*olmv1Alpha.CatalogSource
76-
AllPackageManifests []*PackageManifest
77+
AllPackageManifests []*olmPkgv1.PackageManifest
7778
Deployments []appsv1.Deployment
7879
StatefulSet []appsv1.StatefulSet
7980
PersistentVolumes []corev1.PersistentVolume
@@ -159,7 +160,7 @@ func DoAutoDiscover(config *configuration.TestConfiguration) DiscoveredTestData
159160
}
160161
data.AllInstallPlans = getAllInstallPlans(oc.OlmClient)
161162
data.AllCatalogSources = getAllCatalogSources(oc.OlmClient)
162-
data.AllPackageManifests = getAllPackageManifests(oc.DynamicClient)
163+
data.AllPackageManifests = getAllPackageManifests(oc.OlmPkgClient)
163164
data.Namespaces = namespacesListToStringList(config.TargetNameSpaces)
164165
data.Pods, data.AllPods = findPodsByLabels(oc.K8sClient.CoreV1(), podsUnderTestLabelsObjects, data.Namespaces)
165166
data.AbnormalEvents = findAbnormalEvents(oc.K8sClient.CoreV1(), data.Namespaces)

pkg/autodiscover/autodiscover_operators.go

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,19 @@ package autodiscover
1919
import (
2020
"context"
2121
"fmt"
22-
"time"
2322

2423
helmclient "github.com/mittwald/go-helm-client"
2524
olmv1Alpha "github.com/operator-framework/api/pkg/operators/v1alpha1"
2625
clientOlm "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
2726
"github.com/redhat-best-practices-for-k8s/certsuite/internal/log"
2827
"github.com/redhat-best-practices-for-k8s/certsuite/pkg/configuration"
2928

29+
olmpkgv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/operators/v1"
30+
olmpkgclient "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/client/clientset/versioned/typed/operators/v1"
3031
"github.com/redhat-best-practices-for-k8s/certsuite/pkg/stringhelper"
3132
"helm.sh/helm/v3/pkg/release"
3233
"k8s.io/apimachinery/pkg/api/errors"
3334
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34-
"k8s.io/apimachinery/pkg/runtime"
35-
"k8s.io/apimachinery/pkg/runtime/schema"
36-
"k8s.io/client-go/dynamic"
3735
appv1client "k8s.io/client-go/kubernetes/typed/apps/v1"
3836
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
3937
"k8s.io/client-go/rest"
@@ -44,34 +42,6 @@ const (
4442
istioDeploymentName = "istiod"
4543
)
4644

47-
type PackageManifest struct {
48-
APIVersion string `json:"apiVersion"`
49-
Kind string `json:"kind"`
50-
Metadata struct {
51-
CreationTimestamp time.Time `json:"creationTimestamp"`
52-
Labels map[string]string `json:"labels"`
53-
Name string `json:"name"`
54-
Namespace string `json:"namespace"`
55-
} `json:"metadata"`
56-
Spec struct {
57-
} `json:"spec"`
58-
Status struct {
59-
CatalogSource string `json:"catalogSource"`
60-
CatalogSourceDisplayName string `json:"catalogSourceDisplayName"`
61-
CatalogSourceNamespace string `json:"catalogSourceNamespace"`
62-
CatalogSourcePublisher string `json:"catalogSourcePublisher"`
63-
Channels []struct {
64-
CurrentCSV string `json:"currentCSV"`
65-
Name string `json:"name"`
66-
} `json:"channels"`
67-
DefaultChannel string `json:"defaultChannel"`
68-
PackageName string `json:"packageName"`
69-
Provider struct {
70-
Name string `json:"name"`
71-
} `json:"provider"`
72-
} `json:"status"`
73-
}
74-
7545
func isIstioServiceMeshInstalled(appClient appv1client.AppsV1Interface, allNs []string) bool {
7646
// The Istio namespace must be present
7747
if !stringhelper.StringInSlice(allNs, istioNamespace, false) {
@@ -237,25 +207,14 @@ func getAllCatalogSources(olmClient clientOlm.Interface) (out []*olmv1Alpha.Cata
237207
}
238208

239209
// getAllPackageManifests is a helper function to get the all the PackageManifests in a cluster.
240-
func getAllPackageManifests(dynamicClient dynamic.Interface) (out []*PackageManifest) {
241-
gvr := schema.GroupVersionResource{
242-
Group: "packages.operators.coreos.com",
243-
Version: "v1",
244-
Resource: "packagemanifests",
245-
}
246-
// Query the package manifest for the operator
247-
pkgManifest, err := dynamicClient.Resource(gvr).Namespace("").List(context.TODO(), metav1.ListOptions{})
210+
func getAllPackageManifests(olmPkgClient olmpkgclient.OperatorsV1Interface) (out []*olmpkgv1.PackageManifest) {
211+
packageManifestsList, err := olmPkgClient.PackageManifests("").List(context.TODO(), metav1.ListOptions{})
248212
if err != nil {
249-
log.Error("Unable get PackageManifests in cluster, err: %v", err)
213+
log.Error("Unable get Package Manifests in cluster, err: %v", err)
250214
return out
251215
}
252-
for _, item := range pkgManifest.Items {
253-
var manifest PackageManifest
254-
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(item.Object, &manifest); err != nil {
255-
log.Error("Failed to convert to PackageManifestWithNs: %v", err)
256-
}
257-
258-
out = append(out, &manifest)
216+
for index := range packageManifestsList.Items {
217+
out = append(out, &packageManifestsList.Items[index])
259218
}
260219
return out
261220
}

pkg/provider/operators.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ import (
3030
"github.com/go-logr/stdr"
3131
olmv1 "github.com/operator-framework/api/pkg/operators/v1"
3232
olmv1Alpha "github.com/operator-framework/api/pkg/operators/v1alpha1"
33+
olmpkgv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/operators/v1"
3334
"github.com/redhat-best-practices-for-k8s/certsuite/internal/clientsholder"
3435
"github.com/redhat-best-practices-for-k8s/certsuite/internal/log"
35-
"github.com/redhat-best-practices-for-k8s/certsuite/pkg/autodiscover"
3636
"github.com/redhat-openshift-ecosystem/openshift-preflight/artifacts"
3737
plibRuntime "github.com/redhat-openshift-ecosystem/openshift-preflight/certification"
3838
plibOperator "github.com/redhat-openshift-ecosystem/openshift-preflight/operator"
@@ -151,7 +151,7 @@ func getUniqueCsvListByName(csvs []*olmv1Alpha.ClusterServiceVersion) []*olmv1Al
151151

152152
func createOperators(csvs []*olmv1Alpha.ClusterServiceVersion,
153153
allSubscriptions []olmv1Alpha.Subscription,
154-
allPackageManifests []*autodiscover.PackageManifest,
154+
allPackageManifests []*olmpkgv1.PackageManifest,
155155
allInstallPlans []*olmv1Alpha.InstallPlan,
156156
allCatalogSources []*olmv1Alpha.CatalogSource,
157157
succeededRequired,
@@ -202,7 +202,7 @@ func createOperators(csvs []*olmv1Alpha.ClusterServiceVersion,
202202
return operators
203203
}
204204

205-
func getAtLeastOneSubscription(op *Operator, csv *olmv1Alpha.ClusterServiceVersion, subscriptions []olmv1Alpha.Subscription, packageManifests []*autodiscover.PackageManifest) (atLeastOneSubscription bool) {
205+
func getAtLeastOneSubscription(op *Operator, csv *olmv1Alpha.ClusterServiceVersion, subscriptions []olmv1Alpha.Subscription, packageManifests []*olmpkgv1.PackageManifest) (atLeastOneSubscription bool) {
206206
atLeastOneSubscription = false
207207
for s := range subscriptions {
208208
subscription := &subscriptions[s]
@@ -231,10 +231,10 @@ func getAtLeastOneSubscription(op *Operator, csv *olmv1Alpha.ClusterServiceVersi
231231
return atLeastOneSubscription
232232
}
233233

234-
func getPackageManifestWithSubscription(subscription *olmv1Alpha.Subscription, packageManifests []*autodiscover.PackageManifest) *autodiscover.PackageManifest {
234+
func getPackageManifestWithSubscription(subscription *olmv1Alpha.Subscription, packageManifests []*olmpkgv1.PackageManifest) *olmpkgv1.PackageManifest {
235235
for index := range packageManifests {
236236
if packageManifests[index].Status.PackageName == subscription.Spec.Package &&
237-
packageManifests[index].Metadata.Namespace == subscription.Spec.CatalogSourceNamespace &&
237+
packageManifests[index].Namespace == subscription.Spec.CatalogSourceNamespace &&
238238
packageManifests[index].Status.CatalogSource == subscription.Spec.CatalogSource {
239239
return packageManifests[index]
240240
}

pkg/provider/operators_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"github.com/operator-framework/api/pkg/lib/version"
2424
olmv1 "github.com/operator-framework/api/pkg/operators/v1"
2525
olmv1Alpha "github.com/operator-framework/api/pkg/operators/v1alpha1"
26+
olmpkgv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/operators/v1"
2627
"github.com/redhat-best-practices-for-k8s/certsuite/internal/clientsholder"
27-
"github.com/redhat-best-practices-for-k8s/certsuite/pkg/autodiscover"
2828
"github.com/stretchr/testify/assert"
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030
"k8s.io/apimachinery/pkg/runtime"
@@ -297,7 +297,7 @@ func TestCreateOperators(t *testing.T) {
297297
_ = clientsholder.GetTestClientsHolder(nil)
298298
clientsholder.SetupFakeOlmClient(runtimeObjects)
299299

300-
emptyManifests := []*autodiscover.PackageManifest{}
300+
emptyManifests := []*olmpkgv1.PackageManifest{}
301301
ops := createOperators(tc.csvs, tc.subscriptions, emptyManifests, tc.installPlan, tc.catalogSource, false, true)
302302
assert.Equal(t, tc.expectedOperators, ops)
303303
}

pkg/provider/provider.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
mcv1 "github.com/openshift/api/machineconfiguration/v1"
3030
olmv1 "github.com/operator-framework/api/pkg/operators/v1"
3131
olmv1Alpha "github.com/operator-framework/api/pkg/operators/v1alpha1"
32+
olmpkgv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/operators/v1"
3233
"github.com/redhat-best-practices-for-k8s/certsuite/internal/clientsholder"
3334
"github.com/redhat-best-practices-for-k8s/certsuite/internal/log"
3435
"github.com/redhat-best-practices-for-k8s/certsuite/pkg/autodiscover"
@@ -112,11 +113,11 @@ type TestEnvironment struct { // rename this with testTarget
112113
ResourceQuotas []corev1.ResourceQuota
113114
PodDisruptionBudgets []policyv1.PodDisruptionBudget
114115
NetworkPolicies []networkingv1.NetworkPolicy
115-
AllInstallPlans []*olmv1Alpha.InstallPlan `json:"AllInstallPlans"`
116-
AllSubscriptions []olmv1Alpha.Subscription `json:"AllSubscriptions"`
117-
AllCatalogSources []*olmv1Alpha.CatalogSource `json:"AllCatalogSources"`
118-
AllPackageManifests []*autodiscover.PackageManifest `json:"AllPackageManifests"`
119-
OperatorGroups []*olmv1.OperatorGroup `json:"OperatorGroups"`
116+
AllInstallPlans []*olmv1Alpha.InstallPlan `json:"AllInstallPlans"`
117+
AllSubscriptions []olmv1Alpha.Subscription `json:"AllSubscriptions"`
118+
AllCatalogSources []*olmv1Alpha.CatalogSource `json:"AllCatalogSources"`
119+
AllPackageManifests []*olmpkgv1.PackageManifest `json:"AllPackageManifests"`
120+
OperatorGroups []*olmv1.OperatorGroup `json:"OperatorGroups"`
120121
IstioServiceMeshFound bool
121122
ValidProtocolNames []string
122123
DaemonsetFailedToSpawn bool

0 commit comments

Comments
 (0)