Skip to content

Commit 5cdb317

Browse files
authored
Merge pull request #30081 from stbenjam/migration_complete
NO-JIRA: Add compat_otp package with openshift-tests-private (OTP) util implementation
2 parents 9f7348b + c3a9176 commit 5cdb317

File tree

21,443 files changed

+4721503
-10604
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

21,443 files changed

+4721503
-10604
lines changed

go.mod

Lines changed: 135 additions & 49 deletions
Large diffs are not rendered by default.

go.sum

Lines changed: 332 additions & 78 deletions
Large diffs are not rendered by default.

pkg/monitortests/testframework/knownimagechecker/monitortest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/openshift/origin/pkg/monitortestframework"
1414

15+
exutil "github.com/openshift/origin/test/extended/util"
1516
"github.com/openshift/origin/test/extended/util/image"
1617

1718
monitorserialization "github.com/openshift/origin/pkg/monitor/serialization"
@@ -26,7 +27,6 @@ import (
2627

2728
"github.com/openshift/origin/pkg/monitor/monitorapi"
2829
"github.com/openshift/origin/pkg/test/ginkgo/junitapi"
29-
exutil "github.com/openshift/origin/test/extended/util"
3030
)
3131

3232
const testName = "[sig-arch] Only known images used by tests"

test/extended/util/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ type CLI struct {
8787
verb string
8888
configPath string
8989
adminConfigPath string
90+
guestConfigPath string // Added for OTP compatibility
9091

9192
// directory with static manifests, each file is expected to be a single manifest
9293
// manifest files can be stored under directory tree
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
reviewers:
2+
- aleskandro
3+
- LiangquanLi930
4+
- lwan-wanglin
5+
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
package architecture
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"k8s.io/apimachinery/pkg/util/sets"
8+
9+
g "github.com/onsi/ginkgo/v2"
10+
o "github.com/onsi/gomega"
11+
exutil "github.com/openshift/origin/test/extended/util"
12+
"github.com/openshift/origin/test/extended/util/compat_otp"
13+
e2e "k8s.io/kubernetes/test/e2e/framework"
14+
)
15+
16+
type Architecture int
17+
18+
const (
19+
AMD64 Architecture = iota
20+
ARM64
21+
PPC64LE
22+
S390X
23+
MULTI
24+
UNKNOWN
25+
)
26+
27+
const (
28+
NodeArchitectureLabel = "kubernetes.io/arch"
29+
)
30+
31+
// SkipIfNoNodeWithArchitectures skip the test if the cluster is one of the given architectures
32+
func SkipIfNoNodeWithArchitectures(oc *exutil.CLI, architectures ...Architecture) {
33+
if sets.New(
34+
GetAvailableArchitecturesSet(oc)...).IsSuperset(
35+
sets.New(architectures...)) {
36+
return
37+
}
38+
g.Skip(fmt.Sprintf("Skip for no nodes with requested architectures"))
39+
}
40+
41+
// SkipArchitectures skip the test if the cluster is one of the given architectures
42+
func SkipArchitectures(oc *exutil.CLI, architectures ...Architecture) (architecture Architecture) {
43+
architecture = ClusterArchitecture(oc)
44+
for _, arch := range architectures {
45+
if arch == architecture {
46+
g.Skip(fmt.Sprintf("Skip for cluster architecture: %s", arch.String()))
47+
}
48+
}
49+
return
50+
}
51+
52+
// SkipNonAmd64SingleArch skip the test if the cluster is not an AMD64, single-arch, cluster
53+
func SkipNonAmd64SingleArch(oc *exutil.CLI) (Architecture Architecture) {
54+
architecture := ClusterArchitecture(oc)
55+
if architecture != AMD64 {
56+
g.Skip(fmt.Sprintf("Skip for cluster architecture: %s", architecture.String()))
57+
}
58+
return
59+
}
60+
61+
// GetAvailableArchitecturesSet returns multi-arch node cluster's Architectures
62+
func GetAvailableArchitecturesSet(oc *exutil.CLI) []Architecture {
63+
output, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("nodes", "-o=jsonpath={.items[*].status.nodeInfo.architecture}").Output()
64+
if err != nil {
65+
e2e.Failf("unable to get the cluster architecture: %v", err)
66+
}
67+
if output == "" {
68+
e2e.Failf("the retrieved architecture is empty")
69+
}
70+
architectureList := strings.Split(output, " ")
71+
archMap := make(map[Architecture]bool, 0)
72+
var architectures []Architecture
73+
for _, nodeArchitecture := range architectureList {
74+
if _, ok := archMap[FromString(nodeArchitecture)]; !ok {
75+
archMap[FromString(nodeArchitecture)] = true
76+
architectures = append(architectures, FromString(nodeArchitecture))
77+
}
78+
}
79+
return architectures
80+
}
81+
82+
// SkipNonMultiArchCluster skip the test if the cluster is not an multi-arch cluster
83+
func SkipNonMultiArchCluster(oc *exutil.CLI) {
84+
if !IsMultiArchCluster(oc) {
85+
g.Skip("This cluster is not multi-arch cluster, skip this case!")
86+
}
87+
}
88+
89+
// IsMultiArchCluster check if the cluster is multi-arch cluster
90+
func IsMultiArchCluster(oc *exutil.CLI) bool {
91+
architectures := GetAvailableArchitecturesSet(oc)
92+
return len(architectures) > 1
93+
}
94+
95+
// FromString returns the Architecture value for the given string
96+
func FromString(arch string) Architecture {
97+
switch arch {
98+
case "amd64":
99+
return AMD64
100+
case "arm64":
101+
return ARM64
102+
case "ppc64le":
103+
return PPC64LE
104+
case "s390x":
105+
return S390X
106+
case "multi":
107+
return MULTI
108+
default:
109+
e2e.Failf("Unknown architecture %s", arch)
110+
}
111+
return AMD64
112+
}
113+
114+
// String returns the string value for the given Architecture
115+
func (a Architecture) String() string {
116+
switch a {
117+
case AMD64:
118+
return "amd64"
119+
case ARM64:
120+
return "arm64"
121+
case PPC64LE:
122+
return "ppc64le"
123+
case S390X:
124+
return "s390x"
125+
case MULTI:
126+
return "multi"
127+
default:
128+
e2e.Failf("Unknown architecture %d", a)
129+
}
130+
return ""
131+
}
132+
133+
// ClusterArchitecture returns the cluster's Architecture
134+
// If the cluster uses the multi-arch payload, this function returns Architecture.multi
135+
func ClusterArchitecture(oc *exutil.CLI) (architecture Architecture) {
136+
output, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("nodes", "-o=jsonpath={.items[*].status.nodeInfo.architecture}").Output()
137+
if err != nil {
138+
e2e.Failf("unable to get the cluster architecture: %v", err)
139+
}
140+
if output == "" {
141+
e2e.Failf("the retrieved architecture is empty")
142+
}
143+
architectureList := strings.Split(output, " ")
144+
architecture = FromString(architectureList[0])
145+
for _, nodeArchitecture := range architectureList[1:] {
146+
if FromString(nodeArchitecture) != architecture {
147+
e2e.Logf("Found multi-arch node cluster")
148+
return MULTI
149+
}
150+
}
151+
return
152+
}
153+
154+
func (a Architecture) GNUString() string {
155+
switch a {
156+
case AMD64:
157+
return "x86_64"
158+
case ARM64:
159+
return "aarch64"
160+
case PPC64LE:
161+
return "ppc64le"
162+
case S390X:
163+
return "s390x"
164+
case MULTI:
165+
return "multi"
166+
default:
167+
e2e.Failf("Unknown architecture %d", a)
168+
}
169+
return ""
170+
}
171+
172+
// GetControlPlaneArch get the architecture of the contol plane node
173+
func GetControlPlaneArch(oc *exutil.CLI) Architecture {
174+
masterNode, err := compat_otp.GetFirstMasterNode(oc)
175+
architecture, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("node", masterNode, "-o=jsonpath={.status.nodeInfo.architecture}").Output()
176+
o.Expect(err).NotTo(o.HaveOccurred())
177+
return FromString(architecture)
178+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package compat_otp
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
g "github.com/onsi/ginkgo/v2"
8+
o "github.com/onsi/gomega"
9+
e2e "k8s.io/kubernetes/test/e2e/framework"
10+
)
11+
12+
// e is return value of Wait.Poll
13+
// msg is the reason why time out
14+
// the function assert return value of Wait.Poll, and expect NO error
15+
// if e is Nil, just pass and nothing happen.
16+
// if e is not Nil, will not print the default error message "timed out waiting for the condition" because it causes RP AA not to analysis result exactly.
17+
// if e is "timed out waiting for the condition" or "context deadline exceeded", it is replaced by msg.
18+
// if e is not "timed out waiting for the condition", it print e and then case fails.
19+
20+
func AssertWaitPollNoErr(e error, msg string) {
21+
if e == nil {
22+
return
23+
}
24+
var err error
25+
if strings.Compare(e.Error(), "timed out waiting for the condition") == 0 || strings.Compare(e.Error(), "context deadline exceeded") == 0 {
26+
err = fmt.Errorf("case: %v\nerror: %s", g.CurrentSpecReport().FullText(), msg)
27+
} else {
28+
err = fmt.Errorf("case: %v\nerror: %s", g.CurrentSpecReport().FullText(), e.Error())
29+
}
30+
o.Expect(err).NotTo(o.HaveOccurred())
31+
32+
}
33+
34+
// e is return value of Wait.Poll
35+
// msg is the reason why not get
36+
// the function assert return value of Wait.Poll, and expect error raised.
37+
// if e is not Nil, just pass and nothing happen.
38+
// if e is Nil, will print expected error info and then case fails.
39+
40+
func AssertWaitPollWithErr(e error, msg string) {
41+
if e != nil {
42+
e2e.Logf("the error: %v", e)
43+
return
44+
}
45+
46+
err := fmt.Errorf("case: %v\nexpected error not got because of %v", g.CurrentSpecReport().FullText(), msg)
47+
o.Expect(err).NotTo(o.HaveOccurred())
48+
49+
}
50+
51+
// OrFail function will process another function's return values and fail if any of those returned values is ane error != nil and returns the first value
52+
// example: if we have: func getValued() (string, error)
53+
//
54+
// we can do: value := OrFail[string](getValue())
55+
func OrFail[T any](vals ...any) T {
56+
57+
for _, val := range vals {
58+
err, ok := val.(error)
59+
if ok {
60+
o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred())
61+
}
62+
}
63+
64+
return vals[0].(T)
65+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package compat_otp
2+
3+
import (
4+
rbacinformers "k8s.io/client-go/informers/rbac/v1"
5+
rbacregistryvalidation "k8s.io/kubernetes/pkg/registry/rbac/validation"
6+
rbacauthorizer "k8s.io/kubernetes/plugin/pkg/auth/authorizer/rbac"
7+
)
8+
9+
func NewRuleResolver(informers rbacinformers.Interface) rbacregistryvalidation.AuthorizationRuleResolver {
10+
return rbacregistryvalidation.NewDefaultRuleResolver(
11+
&rbacauthorizer.RoleGetter{Lister: informers.Roles().Lister()},
12+
&rbacauthorizer.RoleBindingLister{Lister: informers.RoleBindings().Lister()},
13+
&rbacauthorizer.ClusterRoleGetter{Lister: informers.ClusterRoles().Lister()},
14+
&rbacauthorizer.ClusterRoleBindingLister{Lister: informers.ClusterRoleBindings().Lister()},
15+
)
16+
}

0 commit comments

Comments
 (0)