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
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ require (
github.com/gosuri/uitable v0.0.4 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0 // indirect
github.com/h2non/filetype v1.1.3 // indirect
github.com/h2non/go-is-svg v0.0.0-20160927212452-35e8c4b0612c // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand Down Expand Up @@ -128,9 +130,11 @@ require (
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/onsi/gomega v1.34.2 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/operator-framework/operator-manifest-tools v0.7.0 // indirect
github.com/operator-framework/operator-registry v1.47.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
Expand Down Expand Up @@ -222,7 +226,7 @@ require (
github.com/gorilla/websocket v1.5.3
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.7.5
github.com/manifoldco/promptui v0.9.0
github.com/redhat-best-practices-for-k8s/oct v0.0.26
github.com/redhat-best-practices-for-k8s/oct v0.0.27
github.com/redhat-best-practices-for-k8s/privileged-daemonset v1.0.39
github.com/redhat-openshift-ecosystem/openshift-preflight v0.0.0-20241021175030-e64988a27024
github.com/robert-nix/ansihtml v1.0.1
Expand Down
98 changes: 75 additions & 23 deletions go.sum

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions internal/clientsholder/clientsholder.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
cncfNetworkAttachmentv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/client/clientset/versioned/typed/k8s.cni.cncf.io/v1"
apiserverscheme "github.com/openshift/client-go/apiserver/clientset/versioned"
ocpMachine "github.com/openshift/client-go/machineconfiguration/clientset/versioned"
olmpkgclient "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/client/clientset/versioned/typed/operators/v1"
appsv1 "k8s.io/api/apps/v1"
scalingv1 "k8s.io/api/autoscaling/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -63,6 +64,7 @@ type ClientsHolder struct {
ScalingClient scale.ScalesGetter
APIExtClient apiextv1.Interface
OlmClient olmClient.Interface
OlmPkgClient olmpkgclient.OperatorsV1Interface
OcpClient clientconfigv1.ConfigV1Interface
K8sClient kubernetes.Interface
K8sNetworkingClient networkingv1.NetworkingV1Interface
Expand Down Expand Up @@ -287,6 +289,10 @@ func newClientsHolder(filenames ...string) (*ClientsHolder, error) { //nolint:fu
if err != nil {
return nil, fmt.Errorf("cannot instantiate olm clientset: %s", err)
}
clientsHolder.OlmPkgClient, err = olmpkgclient.NewForConfig(clientsHolder.RestConfig)
if err != nil {
return nil, fmt.Errorf("cannot instantiate olm clientset: %s", err)
}
clientsHolder.K8sClient, err = kubernetes.NewForConfig(clientsHolder.RestConfig)
if err != nil {
return nil, fmt.Errorf("cannot instantiate k8sclient: %s", err)
Expand Down
3 changes: 3 additions & 0 deletions pkg/autodiscover/autodiscover.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
configv1 "github.com/openshift/api/config/v1"
clientconfigv1 "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
olmv1Alpha "github.com/operator-framework/api/pkg/operators/v1alpha1"
olmPkgv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/operators/v1"
"github.com/redhat-best-practices-for-k8s/certsuite/internal/clientsholder"
"github.com/redhat-best-practices-for-k8s/certsuite/internal/log"
"github.com/redhat-best-practices-for-k8s/certsuite/pkg/compatibility"
Expand Down Expand Up @@ -73,6 +74,7 @@ type DiscoveredTestData struct {
AllCsvs []*olmv1Alpha.ClusterServiceVersion
AllInstallPlans []*olmv1Alpha.InstallPlan
AllCatalogSources []*olmv1Alpha.CatalogSource
AllPackageManifests []*olmPkgv1.PackageManifest
Deployments []appsv1.Deployment
StatefulSet []appsv1.StatefulSet
PersistentVolumes []corev1.PersistentVolume
Expand Down Expand Up @@ -158,6 +160,7 @@ func DoAutoDiscover(config *configuration.TestConfiguration) DiscoveredTestData
}
data.AllInstallPlans = getAllInstallPlans(oc.OlmClient)
data.AllCatalogSources = getAllCatalogSources(oc.OlmClient)
data.AllPackageManifests = getAllPackageManifests(oc.OlmPkgClient)
data.Namespaces = namespacesListToStringList(config.TargetNameSpaces)
data.Pods, data.AllPods = findPodsByLabels(oc.K8sClient.CoreV1(), podsUnderTestLabelsObjects, data.Namespaces)
data.AbnormalEvents = findAbnormalEvents(oc.K8sClient.CoreV1(), data.Namespaces)
Expand Down
16 changes: 16 additions & 0 deletions pkg/autodiscover/autodiscover_operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import (
clientOlm "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
"github.com/redhat-best-practices-for-k8s/certsuite/internal/log"
"github.com/redhat-best-practices-for-k8s/certsuite/pkg/configuration"

olmpkgv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/operators/v1"
olmpkgclient "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/client/clientset/versioned/typed/operators/v1"
"github.com/redhat-best-practices-for-k8s/certsuite/pkg/stringhelper"
"helm.sh/helm/v3/pkg/release"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -202,3 +205,16 @@ func getAllCatalogSources(olmClient clientOlm.Interface) (out []*olmv1Alpha.Cata
}
return out
}

// getAllPackageManifests is a helper function to get the all the PackageManifests in a cluster.
func getAllPackageManifests(olmPkgClient olmpkgclient.OperatorsV1Interface) (out []*olmpkgv1.PackageManifest) {
packageManifestsList, err := olmPkgClient.PackageManifests("").List(context.TODO(), metav1.ListOptions{})
if err != nil {
log.Error("Unable get Package Manifests in cluster, err: %v", err)
return out
}
for index := range packageManifestsList.Items {
out = append(out, &packageManifestsList.Items[index])
}
return out
}
27 changes: 25 additions & 2 deletions pkg/provider/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/go-logr/stdr"
olmv1 "github.com/operator-framework/api/pkg/operators/v1"
olmv1Alpha "github.com/operator-framework/api/pkg/operators/v1alpha1"
olmpkgv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/operators/v1"
"github.com/redhat-best-practices-for-k8s/certsuite/internal/clientsholder"
"github.com/redhat-best-practices-for-k8s/certsuite/internal/log"
"github.com/redhat-openshift-ecosystem/openshift-preflight/artifacts"
Expand Down Expand Up @@ -150,6 +151,7 @@ func getUniqueCsvListByName(csvs []*olmv1Alpha.ClusterServiceVersion) []*olmv1Al

func createOperators(csvs []*olmv1Alpha.ClusterServiceVersion,
allSubscriptions []olmv1Alpha.Subscription,
allPackageManifests []*olmpkgv1.PackageManifest,
allInstallPlans []*olmv1Alpha.InstallPlan,
allCatalogSources []*olmv1Alpha.CatalogSource,
succeededRequired,
Expand Down Expand Up @@ -181,7 +183,7 @@ func createOperators(csvs []*olmv1Alpha.ClusterServiceVersion,
op.PackageFromCsvName = packageAndVersion[0]
op.Version = csv.Spec.Version.String()
// Get at least one subscription and update the Operator object with it.
if getAtLeastOneSubscription(op, csv, allSubscriptions) {
if getAtLeastOneSubscription(op, csv, allSubscriptions, allPackageManifests) {
targetNamespaces, err := getOperatorTargetNamespaces(op.SubscriptionNamespace)
if err != nil {
log.Error("Failed to get target namespaces for operator %s: %v", csv.Name, err)
Expand All @@ -200,7 +202,7 @@ func createOperators(csvs []*olmv1Alpha.ClusterServiceVersion,
return operators
}

func getAtLeastOneSubscription(op *Operator, csv *olmv1Alpha.ClusterServiceVersion, subscriptions []olmv1Alpha.Subscription) (atLeastOneSubscription bool) {
func getAtLeastOneSubscription(op *Operator, csv *olmv1Alpha.ClusterServiceVersion, subscriptions []olmv1Alpha.Subscription, packageManifests []*olmpkgv1.PackageManifest) (atLeastOneSubscription bool) {
atLeastOneSubscription = false
for s := range subscriptions {
subscription := &subscriptions[s]
Expand All @@ -214,11 +216,32 @@ func getAtLeastOneSubscription(op *Operator, csv *olmv1Alpha.ClusterServiceVersi
op.Org = subscription.Spec.CatalogSource
op.Channel = subscription.Spec.Channel
atLeastOneSubscription = true

// If the channel is not present in the subscription, get the default channel from the package manifest
if op.Channel == "" {
aPackageManifest := getPackageManifestWithSubscription(subscription, packageManifests)
if aPackageManifest != nil {
op.Channel = aPackageManifest.Status.DefaultChannel
} else {
log.Error("Could not determine the default channel, this operator will always fail certification")
}
}
break
}
return atLeastOneSubscription
}

func getPackageManifestWithSubscription(subscription *olmv1Alpha.Subscription, packageManifests []*olmpkgv1.PackageManifest) *olmpkgv1.PackageManifest {
for index := range packageManifests {
if packageManifests[index].Status.PackageName == subscription.Spec.Package &&
packageManifests[index].Namespace == subscription.Spec.CatalogSourceNamespace &&
packageManifests[index].Status.CatalogSource == subscription.Spec.CatalogSource {
return packageManifests[index]
}
}
return nil
}

func getAtLeastOneCsv(csv *olmv1Alpha.ClusterServiceVersion, installPlan *olmv1Alpha.InstallPlan) (atLeastOneCsv bool) {
atLeastOneCsv = false
for _, csvName := range installPlan.Spec.ClusterServiceVersionNames {
Expand Down
4 changes: 3 additions & 1 deletion pkg/provider/operators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/operator-framework/api/pkg/lib/version"
olmv1 "github.com/operator-framework/api/pkg/operators/v1"
olmv1Alpha "github.com/operator-framework/api/pkg/operators/v1alpha1"
olmpkgv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/operators/v1"
"github.com/redhat-best-practices-for-k8s/certsuite/internal/clientsholder"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -296,7 +297,8 @@ func TestCreateOperators(t *testing.T) {
_ = clientsholder.GetTestClientsHolder(nil)
clientsholder.SetupFakeOlmClient(runtimeObjects)

ops := createOperators(tc.csvs, tc.subscriptions, tc.installPlan, tc.catalogSource, false, true)
emptyManifests := []*olmpkgv1.PackageManifest{}
ops := createOperators(tc.csvs, tc.subscriptions, emptyManifests, tc.installPlan, tc.catalogSource, false, true)
assert.Equal(t, tc.expectedOperators, ops)
}
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
mcv1 "github.com/openshift/api/machineconfiguration/v1"
olmv1 "github.com/operator-framework/api/pkg/operators/v1"
olmv1Alpha "github.com/operator-framework/api/pkg/operators/v1alpha1"
olmpkgv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/operators/v1"
"github.com/redhat-best-practices-for-k8s/certsuite/internal/clientsholder"
"github.com/redhat-best-practices-for-k8s/certsuite/internal/log"
"github.com/redhat-best-practices-for-k8s/certsuite/pkg/autodiscover"
Expand Down Expand Up @@ -114,7 +115,8 @@ type TestEnvironment struct { // rename this with testTarget
NetworkPolicies []networkingv1.NetworkPolicy
AllInstallPlans []*olmv1Alpha.InstallPlan `json:"AllInstallPlans"`
AllSubscriptions []olmv1Alpha.Subscription `json:"AllSubscriptions"`
AllCatalogSources []*olmv1Alpha.CatalogSource `json:"-"`
AllCatalogSources []*olmv1Alpha.CatalogSource `json:"AllCatalogSources"`
AllPackageManifests []*olmpkgv1.PackageManifest `json:"AllPackageManifests"`
OperatorGroups []*olmv1.OperatorGroup `json:"OperatorGroups"`
IstioServiceMeshFound bool
ValidProtocolNames []string
Expand Down Expand Up @@ -240,7 +242,8 @@ func buildTestEnvironment() { //nolint:funlen
}
env.AllSubscriptions = data.AllSubscriptions
env.AllCatalogSources = data.AllCatalogSources
env.AllOperators = createOperators(data.AllCsvs, data.AllSubscriptions, data.AllInstallPlans, data.AllCatalogSources, false, true)
env.AllPackageManifests = data.AllPackageManifests
env.AllOperators = createOperators(data.AllCsvs, data.AllSubscriptions, data.AllPackageManifests, data.AllInstallPlans, data.AllCatalogSources, false, true)
env.AllOperatorsSummary = getSummaryAllOperators(env.AllOperators)
env.AllCrds = data.AllCrds
env.Namespaces = data.Namespaces
Expand Down Expand Up @@ -344,7 +347,7 @@ func buildTestEnvironment() { //nolint:funlen
env.CollectorAppPassword = data.CollectorAppPassword
env.CollectorAppEndpoint = data.CollectorAppEndpoint

operators := createOperators(data.Csvs, data.AllSubscriptions,
operators := createOperators(data.Csvs, data.AllSubscriptions, data.AllPackageManifests,
data.AllInstallPlans, data.AllCatalogSources, false, true)
env.Operators = operators
log.Info("Operators found: %d", len(env.Operators))
Expand Down
2 changes: 1 addition & 1 deletion tests/certification/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func testAllOperatorCertified(check *checksdb.Check, env *provider.TestEnvironme
}
for _, operator := range operatorsUnderTest {
check.LogInfo("Testing Operator %q", operator)
isCertified := validator.IsOperatorCertified(operator.Name, ocpMinorVersion, operator.Channel)
isCertified := validator.IsOperatorCertified(operator.Name, ocpMinorVersion)
if !isCertified {
check.LogError("Operator %q (channel %q) failed to be certified for OpenShift %s", operator.Name, operator.Channel, ocpMinorVersion)
nonCompliantObjects = append(nonCompliantObjects, testhelper.NewOperatorReportObject(operator.Namespace, operator.Name, "Operator failed to be certified for OpenShift", false).
Expand Down
Loading