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
46 changes: 27 additions & 19 deletions cmd/openshift-tests/openshift-tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,39 @@ package main
import (
"flag"
"fmt"
"math/rand"
"os"
"os/exec"
"syscall"
"time"

"github.com/openshift-eng/openshift-tests-extension/pkg/cmd/cmdinfo"
"github.com/openshift-eng/openshift-tests-extension/pkg/cmd/cmdrun"
"github.com/openshift/library-go/pkg/serviceability"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/cli-runtime/pkg/genericclioptions"
utilflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"
"k8s.io/kubectl/pkg/util/templates"

"github.com/openshift/origin/pkg/cmd"
collectdiskcertificates "github.com/openshift/origin/pkg/cmd/openshift-tests/collect-disk-certificates"
"github.com/openshift/origin/pkg/cmd/openshift-tests/dev"
"github.com/openshift/origin/pkg/cmd/openshift-tests/disruption"
"github.com/openshift/origin/pkg/cmd/openshift-tests/images"
"github.com/openshift/origin/pkg/cmd/openshift-tests/list"
"github.com/openshift/origin/pkg/cmd/openshift-tests/monitor"
run_monitor "github.com/openshift/origin/pkg/cmd/openshift-tests/monitor/run"
"github.com/openshift/origin/pkg/cmd/openshift-tests/monitor/timeline"
"github.com/openshift/origin/pkg/cmd/openshift-tests/render"
risk_analysis "github.com/openshift/origin/pkg/cmd/openshift-tests/risk-analysis"
"github.com/openshift/origin/pkg/cmd/openshift-tests/run"
run_disruption "github.com/openshift/origin/pkg/cmd/openshift-tests/run-disruption"
run_test "github.com/openshift/origin/pkg/cmd/openshift-tests/run-test"
run_upgrade "github.com/openshift/origin/pkg/cmd/openshift-tests/run-upgrade"
"github.com/openshift/origin/pkg/cmd/openshift-tests/run_resource_watch"
versioncmd "github.com/openshift/origin/pkg/cmd/openshift-tests/version"
testginkgo "github.com/openshift/origin/pkg/test/ginkgo"
"github.com/openshift/origin/pkg/test/extensions"
exutil "github.com/openshift/origin/test/extended/util"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/cli-runtime/pkg/genericclioptions"
utilflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"
"k8s.io/kubectl/pkg/util/templates"
)

func main() {
Expand All @@ -53,14 +54,23 @@ func main() {

logs.InitLogs()
defer logs.FlushLogs()

logrus.SetLevel(logrus.InfoLevel)

rand.Seed(time.Now().UTC().UnixNano())
// The GCE PD drivers were removed in kube 1.31, so we can ignore the env var that
// some automation sets.
if os.Getenv("ENABLE_STORAGE_GCE_PD_DRIVER") != "" {
logrus.Warn("ENABLE_STORAGE_GCE_PD_DRIVER is set, but is not supported")
os.Unsetenv("ENABLE_STORAGE_GCE_PD_DRIVER")
}

pflag.CommandLine.SetNormalizeFunc(utilflag.WordSepNormalizeFunc)
//pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)

extensionRegistry, originExtension, err := extensions.InitializeOpenShiftTestsExtensionFramework()
if err != nil {
panic(err)
}

root := &cobra.Command{
Long: templates.LongDesc(`This command verifies behavior of an OpenShift cluster by running remote tests against
the cluster API that exercise functionality. In general these tests may be disruptive
Expand All @@ -79,10 +89,12 @@ func main() {
}

root.AddCommand(
run.NewRunCommand(ioStreams),
run.NewRunCommand(ioStreams, originExtension),
list.NewListCommand(ioStreams, extensionRegistry),
cmdinfo.NewInfoCommand(extensionRegistry),
run_upgrade.NewRunUpgradeCommand(ioStreams),
images.NewImagesCommand(),
run_test.NewRunTestCommand(ioStreams),
cmdrun.NewRunTestCommand(extensionRegistry),
dev.NewDevCommand(),
run_monitor.NewRunMonitorCommand(ioStreams),
monitor.NewMonitorCommand(ioStreams),
Expand All @@ -106,10 +118,6 @@ func main() {
defer serviceability.Profile(os.Getenv("OPENSHIFT_PROFILE")).Stop()
return root.Execute()
}(); err != nil {
if ex, ok := err.(testginkgo.ExitError); ok {
fmt.Fprintf(os.Stderr, "Ginkgo exit error %d: %v\n", ex.Code, err)
os.Exit(ex.Code)
}
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ require (
github.com/onsi/ginkgo/v2 v2.21.0
github.com/onsi/gomega v1.35.1
github.com/opencontainers/go-digest v1.0.0
github.com/openshift-eng/openshift-tests-extension v0.0.0-20250522124649-4ffcd156ec7c
github.com/openshift-kni/commatrix v0.0.4-0.20250604173218-064b4004e9fb
github.com/openshift/api v0.0.0-20250513132935-9052dea86694
github.com/openshift/apiserver-library-go v0.0.0-20250127121756-dc9a973f14ce
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,8 @@ github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE
github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opencontainers/selinux v1.11.1 h1:nHFvthhM0qY8/m+vfhJylliSshm8G1jJ2jDMcgULaH8=
github.com/opencontainers/selinux v1.11.1/go.mod h1:E5dMC3VPuVvVHDYmi78qvhJp8+M586T4DlDRYpFkyec=
github.com/openshift-eng/openshift-tests-extension v0.0.0-20250220212757-b9c4d98a0c45 h1:hXpbYtP3iTh8oy/RKwKkcMziwchY3fIk95ciczf7cOA=
github.com/openshift-eng/openshift-tests-extension v0.0.0-20250220212757-b9c4d98a0c45/go.mod h1:6gkP5f2HL0meusT0Aim8icAspcD1cG055xxBZ9yC68M=
github.com/openshift-eng/openshift-tests-extension v0.0.0-20250522124649-4ffcd156ec7c h1:R5dI2oOF2RtS1sKtLrhW9KMg0ydzF0XM2Q//ma55nWI=
github.com/openshift-eng/openshift-tests-extension v0.0.0-20250522124649-4ffcd156ec7c/go.mod h1:6gkP5f2HL0meusT0Aim8icAspcD1cG055xxBZ9yC68M=
github.com/openshift-kni/commatrix v0.0.4-0.20250604173218-064b4004e9fb h1:+owPvmRBKN5dYuVQ7/CROW0h6wL6Hk8MJlf2vnZQfSM=
github.com/openshift-kni/commatrix v0.0.4-0.20250604173218-064b4004e9fb/go.mod h1:R8JhlXqlLwe3N6nQheK2KpMEESIlDVCUw5TOLKiZ08s=
github.com/openshift/api v0.0.0-20250513132935-9052dea86694 h1:kPnk1+m89LJHexYsTP+MVM9OgJLxcpUR3vRdMQNF66s=
Expand Down
166 changes: 108 additions & 58 deletions pkg/clioptions/clusterdiscovery/cluster.go
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm adding feature gates and api groups to the cluster state, and removing the test filtering from this code. It goes to pkg/test/filters/cluster_state.go

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import (
"io/ioutil"
"net/http"
"net/url"
"slices"
"strings"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/runtime/schema"

corev1 "k8s.io/api/core/v1"
Expand All @@ -22,6 +25,7 @@ import (
operatorv1 "github.com/openshift/api/operator/v1"
configclient "github.com/openshift/client-go/config/clientset/versioned"
operatorclient "github.com/openshift/client-go/operator/clientset/versioned"

"github.com/openshift/origin/test/extended/util/azure"
)

Expand Down Expand Up @@ -70,6 +74,13 @@ type ClusterConfiguration struct {

// IsNoOptionalCapabilities indicates the cluster has no optional capabilities enabled
HasNoOptionalCapabilities bool

// APIGroups contains the set of API groups available in the cluster
APIGroups sets.Set[string] `json:"-"`
// EnabledFeatureGates contains the set of enabled feature gates in the cluster
EnabledFeatureGates sets.Set[string] `json:"-"`
// DisabledFeatureGates contains the set of disabled feature gates in the cluster
DisabledFeatureGates sets.Set[string] `json:"-"`
}

func (c *ClusterConfiguration) ToJSONString() string {
Expand All @@ -91,6 +102,80 @@ type ClusterState struct {
ControlPlaneTopology *configv1.TopologyMode
OptionalCapabilities []configv1.ClusterVersionCapability
Version *configv1.ClusterVersion
APIGroups sets.Set[string]
EnabledFeatureGates sets.Set[string]
DisabledFeatureGates sets.Set[string]
}

// discoverAPIGroups discovers available API groups in the cluster
func discoverAPIGroups(coreClient clientset.Interface) (sets.Set[string], error) {
logrus.Debugf("Discovering API Groups...")
discoveryClient := coreClient.Discovery()
groups, err := discoveryClient.ServerGroups()
if err != nil {
return nil, err
}

apiGroups := sets.New[string]()
for _, apiGroup := range groups.Groups {
// ignore the empty group
if apiGroup.Name == "" {
continue
}
apiGroups.Insert(apiGroup.Name)
}

sortedAPIGroups := apiGroups.UnsortedList()
slices.Sort(sortedAPIGroups)

logrus.WithField("apiGroups", strings.Join(sortedAPIGroups, ", ")).
Debugf("Discovered %d API Groups", apiGroups.Len())

return apiGroups, nil
}

// discoverFeatureGates discovers feature gates in the cluster
func discoverFeatureGates(configClient configclient.Interface, clusterVersion *configv1.ClusterVersion) (enabled, disabled sets.Set[string], err error) {
logrus.Debugf("Discovering feature gates...")
featureGate, err := configClient.ConfigV1().FeatureGates().Get(context.Background(), "cluster", metav1.GetOptions{})
if err != nil {
return nil, nil, errors.WithMessage(err, "encountered an error while discovering feature gates")
}

desiredVersion := clusterVersion.Status.Desired.Version
if len(desiredVersion) == 0 && len(clusterVersion.Status.History) > 0 {
desiredVersion = clusterVersion.Status.History[0].Version
}

enabled = sets.New[string]()
disabled = sets.New[string]()
for _, featureGateValues := range featureGate.Status.FeatureGates {
if featureGateValues.Version != desiredVersion {
logrus.Warningf("Feature gates for version %s not found, skipping", desiredVersion)
continue
}
for _, enabledGate := range featureGateValues.Enabled {
enabled.Insert(string(enabledGate.Name))
}
for _, disabledGate := range featureGateValues.Disabled {
disabled.Insert(string(disabledGate.Name))
}
break
}

sortedEnabledGates := enabled.UnsortedList()
slices.Sort(sortedEnabledGates)

logrus.WithField("featureGates", strings.Join(sortedEnabledGates, ", ")).
Debugf("Discovered %d enabled feature gates", len(sortedEnabledGates))

sortedDisabledGates := disabled.UnsortedList()
slices.Sort(sortedDisabledGates)

logrus.WithField("featureGates", strings.Join(sortedDisabledGates, ", ")).
Debugf("Discovered %d disabled feature gates", len(sortedDisabledGates))

return enabled, disabled, nil
}

// DiscoverClusterState creates a ClusterState based on a live cluster
Expand Down Expand Up @@ -156,6 +241,24 @@ func DiscoverClusterState(clientConfig *rest.Config) (*ClusterState, error) {
state.Version = clusterVersion
state.OptionalCapabilities = clusterVersion.Status.Capabilities.EnabledCapabilities

// Discover available API groups
state.APIGroups, err = discoverAPIGroups(coreClient)
if err != nil {
return nil, errors.WithMessage(err, "encountered an error while discovering API groups")
}

// Discover feature gates
if state.APIGroups.Has("config.openshift.io") {
state.EnabledFeatureGates, state.DisabledFeatureGates, err = discoverFeatureGates(configClient, clusterVersion)
if err != nil {
logrus.WithError(err).Warn("ignoring error from discoverFeatureGates")
}
} else {
state.EnabledFeatureGates = sets.New[string]()
state.DisabledFeatureGates = sets.New[string]()
logrus.Infof("config.openshift.io API group not found, skipping feature gate discovery")
}

return state, nil
}

Expand Down Expand Up @@ -271,63 +374,10 @@ func LoadConfig(state *ClusterState) (*ClusterConfiguration, error) {
// have to scan MachineConfig objects to figure this out? For now, callers can
// can just manually override with --provider...

return config, nil
}

// MatchFn returns a function that tests if a named function should be run based on
// the cluster configuration
func (c *ClusterConfiguration) MatchFn() func(string) bool {
var skips []string
skips = append(skips, fmt.Sprintf("[Skipped:%s]", c.ProviderName))

if c.IsIBMROKS {
skips = append(skips, "[Skipped:ibmroks]")
}
if c.NetworkPlugin != "" {
skips = append(skips, fmt.Sprintf("[Skipped:Network/%s]", c.NetworkPlugin))
if c.NetworkPluginMode != "" {
skips = append(skips, fmt.Sprintf("[Skipped:Network/%s/%s]", c.NetworkPlugin, c.NetworkPluginMode))
}
}

if c.Disconnected {
skips = append(skips, "[Skipped:Disconnected]")
}
// Copy API groups and feature gates from cluster state
config.APIGroups = state.APIGroups
config.EnabledFeatureGates = state.EnabledFeatureGates
config.DisabledFeatureGates = state.DisabledFeatureGates

if c.IsProxied {
skips = append(skips, "[Skipped:Proxy]")
}

if c.SingleReplicaTopology {
skips = append(skips, "[Skipped:SingleReplicaTopology]")
}

if !c.HasIPv4 {
skips = append(skips, "[Feature:Networking-IPv4]")
}
if !c.HasIPv6 {
skips = append(skips, "[Feature:Networking-IPv6]")
}
if !c.HasIPv4 || !c.HasIPv6 {
// lack of "]" is intentional; this matches multiple tags
skips = append(skips, "[Feature:IPv6DualStack")
}

if !c.HasSCTP {
skips = append(skips, "[Feature:SCTPConnectivity]")
}

if c.HasNoOptionalCapabilities {
skips = append(skips, "[Skipped:NoOptionalCapabilities]")
}

matchFn := func(name string) bool {
for _, skip := range skips {
if strings.Contains(name, skip) {
return false
}
}
return true
}
return matchFn
return config, nil
}
9 changes: 6 additions & 3 deletions pkg/clioptions/clusterdiscovery/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"github.com/onsi/gomega"
"github.com/sirupsen/logrus"

"github.com/openshift/origin/test/extended/util/image"
e2e "k8s.io/kubernetes/test/e2e/framework"

"github.com/openshift/origin/test/extended/util/image"

exutil "github.com/openshift/origin/test/extended/util"
// Initialize baremetal as a provider
_ "github.com/openshift/origin/test/extended/util/baremetal"
Expand Down Expand Up @@ -104,7 +105,7 @@ func DecodeProvider(providerTypeOrJSON string, dryRun, discover bool, clusterSta
"dryRun": dryRun,
"discover": discover,
"clusterState": clusterState,
}).Info("Decoding provider")
}).Debug("Decoding provider")
switch providerTypeOrJSON {
case "none":
config := &ClusterConfiguration{
Expand Down Expand Up @@ -193,7 +194,9 @@ func DecodeProvider(providerTypeOrJSON string, dryRun, discover bool, clusterSta
if clusterState != nil {
var err error
config, err = LoadConfig(clusterState)
log.WithError(err).Warn("ignoring error from LoadConfig for discovery")
if err != nil {
log.WithError(err).Warn("ignoring error from LoadConfig for discovery")
}
Comment on lines +197 to +199
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing an old bug, we always logged an error

}
}
if config == nil {
Expand Down
Loading