Skip to content

Commit 0576352

Browse files
committed
KMS TESTING
1 parent d91ce38 commit 0576352

File tree

8 files changed

+2229
-14
lines changed

8 files changed

+2229
-14
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[
2+
{
3+
"name": "[Jira:kube-apiserver][sig-api-machinery][FeatureGate:EventTTL] Event TTL Configuration should configure and validate eventTTLMinutes=5m [Timeout:90m][Serial][Disruptive][Slow][Suite:openshift/cluster-kube-apiserver-operator/conformance/serial]",
4+
"labels": {
5+
"Lifecycle:informing": {}
6+
},
7+
"tags": {
8+
"timeout": "90m"
9+
},
10+
"resources": {
11+
"isolation": {}
12+
},
13+
"source": "openshift:payload:cluster-kube-apiserver-operator",
14+
"lifecycle": "informing",
15+
"environmentSelector": {}
16+
},
17+
{
18+
"name": "[Jira:kube-apiserver][sig-api-machinery][FeatureGate:EventTTL] Event TTL Configuration should configure and validate eventTTLMinutes=10m [Timeout:90m][Serial][Disruptive][Slow][Suite:openshift/cluster-kube-apiserver-operator/conformance/serial]",
19+
"labels": {
20+
"Lifecycle:informing": {}
21+
},
22+
"tags": {
23+
"timeout": "90m"
24+
},
25+
"resources": {
26+
"isolation": {}
27+
},
28+
"source": "openshift:payload:cluster-kube-apiserver-operator",
29+
"lifecycle": "informing",
30+
"environmentSelector": {}
31+
},
32+
{
33+
"name": "[Jira:kube-apiserver][sig-api-machinery][FeatureGate:EventTTL] Event TTL Configuration should configure and validate eventTTLMinutes=15m [Timeout:90m][Serial][Disruptive][Slow][Suite:openshift/cluster-kube-apiserver-operator/conformance/serial]",
34+
"labels": {
35+
"Lifecycle:informing": {}
36+
},
37+
"tags": {
38+
"timeout": "90m"
39+
},
40+
"resources": {
41+
"isolation": {}
42+
},
43+
"source": "openshift:payload:cluster-kube-apiserver-operator",
44+
"lifecycle": "informing",
45+
"environmentSelector": {}
46+
},
47+
{
48+
"name": "[Jira:kube-apiserver][sig-api-machinery] sanity test should always pass [Suite:openshift/cluster-kube-apiserver-operator/conformance/parallel]",
49+
"labels": {},
50+
"resources": {
51+
"isolation": {}
52+
},
53+
"source": "openshift:payload:cluster-kube-apiserver-operator",
54+
"lifecycle": "blocking",
55+
"environmentSelector": {}
56+
}
57+
]
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package extended
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
"strings"
8+
9+
g "github.com/onsi/ginkgo/v2"
10+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
"k8s.io/client-go/dynamic"
12+
"k8s.io/client-go/kubernetes"
13+
)
14+
15+
// YamlKmsTestCase represents a KMS test case from YAML
16+
type YamlKmsTestCase struct {
17+
Name string `yaml:"name"`
18+
Initial string `yaml:"initial"`
19+
Expected string `yaml:"expected,omitempty"`
20+
ExpectedError string `yaml:"expectedError,omitempty"`
21+
}
22+
23+
// ComputeNode interface to handle compute nodes across different cloud platforms
24+
type ComputeNode interface {
25+
GetName() string
26+
GetInstanceID() (string, error)
27+
CreateKMSKey() string
28+
DeleteKMSKey(keyArn string)
29+
LoadKMSTestCasesFromYAML() ([]YamlKmsTestCase, error)
30+
GetIamRoleNameFromId() string
31+
RenderKmsKeyPolicy() string
32+
UpdateKmsPolicy(keyID string)
33+
GetRegionFromARN(arn string) string
34+
VerifyEncryptionType(ctx context.Context, client dynamic.Interface) (string, bool)
35+
VerifySecretEncryption(ctx context.Context, namespace, secretName string) (bool, string)
36+
VerifyOAuthTokenEncryption(ctx context.Context, tokenType, tokenName string) (bool, string)
37+
ExecuteCommand(command string) (string, error)
38+
}
39+
40+
// instance is the base struct for all compute node implementations
41+
type instance struct {
42+
nodeName string
43+
kubeClient *kubernetes.Clientset
44+
dynamicClient dynamic.Interface
45+
ctx context.Context
46+
}
47+
48+
func (i *instance) GetName() string {
49+
return i.nodeName
50+
}
51+
52+
// ExecuteCommand executes a command on the node via oc debug
53+
func (i *instance) ExecuteCommand(command string) (string, error) {
54+
// Use the executeNodeCommand wrapper from util.go
55+
return executeNodeCommand(i.nodeName, command)
56+
}
57+
58+
// ComputeNodes handles a collection of ComputeNode interfaces
59+
type ComputeNodes []ComputeNode
60+
61+
// GetNodes gets master nodes according to platform with the specified label
62+
func GetNodes(ctx context.Context, kubeClient *kubernetes.Clientset, dynamicClient dynamic.Interface, label string) (ComputeNodes, func()) {
63+
platform := checkPlatform(kubeClient)
64+
65+
switch platform {
66+
case "aws":
67+
return GetAwsNodes(ctx, kubeClient, dynamicClient, label)
68+
case "gcp":
69+
g.Skip("GCP platform KMS support not yet implemented")
70+
return nil, nil
71+
case "azure":
72+
g.Skip("Azure platform KMS support not yet implemented")
73+
return nil, nil
74+
default:
75+
g.Skip(fmt.Sprintf("Platform %s is not supported for KMS tests. Expected AWS, GCP, or Azure.", platform))
76+
return nil, nil
77+
}
78+
}
79+
80+
// checkPlatform determines the cloud platform of the cluster
81+
func checkPlatform(kubeClient *kubernetes.Clientset) string {
82+
// Check for AWS-specific labels or annotations
83+
nodes, err := kubeClient.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{Limit: 1})
84+
if err != nil || len(nodes.Items) == 0 {
85+
return "unknown"
86+
}
87+
88+
node := nodes.Items[0]
89+
90+
// Check provider ID format
91+
if providerID := node.Spec.ProviderID; providerID != "" {
92+
if strings.HasPrefix(providerID, "aws://") {
93+
return "aws"
94+
}
95+
if strings.HasPrefix(providerID, "gce://") {
96+
return "gcp"
97+
}
98+
if strings.HasPrefix(providerID, "azure://") {
99+
return "azure"
100+
}
101+
}
102+
103+
return "unknown"
104+
}
105+
106+
// getAWSRegion gets the AWS region from environment or config
107+
func getAWSRegion() string {
108+
if region := os.Getenv("AWS_REGION"); region != "" {
109+
return region
110+
}
111+
// Default to us-east-1 if not specified
112+
return "us-east-1"
113+
}

0 commit comments

Comments
 (0)