@@ -19,21 +19,19 @@ package autodiscover
1919import (
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-
7545func 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}
0 commit comments