@@ -20,19 +20,19 @@ import (
20
20
"context"
21
21
"fmt"
22
22
23
+ "sigs.k8s.io/e2e-framework/pkg/utils"
24
+
23
25
"sigs.k8s.io/e2e-framework/pkg/env"
24
26
"sigs.k8s.io/e2e-framework/pkg/envconf"
25
27
"sigs.k8s.io/e2e-framework/support"
26
28
)
27
29
28
- type clusterNameContextKey string
29
-
30
30
var LoadDockerImageToCluster = LoadImageToCluster
31
31
32
32
// GetClusterFromContext helps extract the E2EClusterProvider object from the context.
33
33
// This can be used to setup and run tests of multi cluster e2e Prioviders.
34
34
func GetClusterFromContext (ctx context.Context , clusterName string ) (support.E2EClusterProvider , bool ) {
35
- c := ctx .Value (clusterNameContextKey (clusterName ))
35
+ c := ctx .Value (support . ClusterNameContextKey (clusterName ))
36
36
if c == nil {
37
37
return nil , false
38
38
}
@@ -47,8 +47,19 @@ func GetClusterFromContext(ctx context.Context, clusterName string) (support.E2E
47
47
// NOTE: the returned function will update its env config with the
48
48
// kubeconfig file for the config client.
49
49
func CreateCluster (p support.E2EClusterProvider , clusterName string ) env.Func {
50
+ return CreateClusterWithOpts (p , clusterName )
51
+ }
52
+
53
+ // CreateClusterWithOpts returns an env.Func that is used to
54
+ // create an E2E provider cluster that is then injected in the context
55
+ // using the name as a key. This can be provided with additional opts to extend the create
56
+ // workflow of the cluster.
57
+ //
58
+ // NOTE: the returned function will update its env config with the
59
+ // kubeconfig file for the config client.
60
+ func CreateClusterWithOpts (p support.E2EClusterProvider , clusterName string , opts ... support.ClusterOpts ) env.Func {
50
61
return func (ctx context.Context , cfg * envconf.Config ) (context.Context , error ) {
51
- k := p .SetDefaults ().WithName (clusterName )
62
+ k := p .SetDefaults ().WithName (clusterName ). WithOpts ( opts ... )
52
63
kubecfg , err := k .Create (ctx )
53
64
if err != nil {
54
65
return ctx , err
@@ -63,7 +74,7 @@ func CreateCluster(p support.E2EClusterProvider, clusterName string) env.Func {
63
74
}
64
75
65
76
// store entire cluster value in ctx for future access using the cluster name
66
- return context .WithValue (ctx , clusterNameContextKey (clusterName ), k ), nil
77
+ return context .WithValue (ctx , support . ClusterNameContextKey (clusterName ), k ), nil
67
78
}
68
79
}
69
80
@@ -90,7 +101,7 @@ func CreateClusterWithConfig(p support.E2EClusterProvider, clusterName, configFi
90
101
}
91
102
92
103
// store entire cluster value in ctx for future access using the cluster name
93
- return context .WithValue (ctx , clusterNameContextKey (clusterName ), k ), nil
104
+ return context .WithValue (ctx , support . ClusterNameContextKey (clusterName ), k ), nil
94
105
}
95
106
}
96
107
@@ -100,7 +111,7 @@ func CreateClusterWithConfig(p support.E2EClusterProvider, clusterName, configFi
100
111
// NOTE: this should be used in a Environment.Finish step.
101
112
func DestroyCluster (name string ) env.Func {
102
113
return func (ctx context.Context , cfg * envconf.Config ) (context.Context , error ) {
103
- clusterVal := ctx .Value (clusterNameContextKey (name ))
114
+ clusterVal := ctx .Value (support . ClusterNameContextKey (name ))
104
115
if clusterVal == nil {
105
116
return ctx , fmt .Errorf ("destroy e2e provider cluster func: context cluster is nil" )
106
117
}
@@ -121,9 +132,9 @@ func DestroyCluster(name string) env.Func {
121
132
// LoadImageToCluster returns an EnvFunc that
122
133
// retrieves a previously saved e2e provider Cluster in the context (using the name), and then loads a container image
123
134
// from the host into the cluster.
124
- func LoadImageToCluster (name , image string ) env.Func {
135
+ func LoadImageToCluster (name , image string , args ... string ) env.Func {
125
136
return func (ctx context.Context , cfg * envconf.Config ) (context.Context , error ) {
126
- clusterVal := ctx .Value (clusterNameContextKey (name ))
137
+ clusterVal := ctx .Value (support . ClusterNameContextKey (name ))
127
138
if clusterVal == nil {
128
139
return ctx , fmt .Errorf ("load image func: context cluster is nil" )
129
140
}
@@ -133,7 +144,7 @@ func LoadImageToCluster(name, image string) env.Func {
133
144
return ctx , fmt .Errorf ("load image archive func: cluster provider does not support LoadImage helper" )
134
145
}
135
146
136
- if err := cluster .LoadImage (ctx , image ); err != nil {
147
+ if err := cluster .LoadImage (ctx , image , args ... ); err != nil {
137
148
return ctx , fmt .Errorf ("load image: %w" , err )
138
149
}
139
150
@@ -144,9 +155,9 @@ func LoadImageToCluster(name, image string) env.Func {
144
155
// LoadImageArchiveToCluster returns an EnvFunc that
145
156
// retrieves a previously saved e2e provider Cluster in the context (using the name), and then loads a container image TAR archive
146
157
// from the host into the cluster.
147
- func LoadImageArchiveToCluster (name , imageArchive string ) env.Func {
158
+ func LoadImageArchiveToCluster (name , imageArchive string , args ... string ) env.Func {
148
159
return func (ctx context.Context , cfg * envconf.Config ) (context.Context , error ) {
149
- clusterVal := ctx .Value (clusterNameContextKey (name ))
160
+ clusterVal := ctx .Value (support . ClusterNameContextKey (name ))
150
161
if clusterVal == nil {
151
162
return ctx , fmt .Errorf ("load image archive func: context cluster is nil" )
152
163
}
@@ -156,7 +167,7 @@ func LoadImageArchiveToCluster(name, imageArchive string) env.Func {
156
167
return ctx , fmt .Errorf ("load image archive func: cluster provider does not support LoadImageArchive helper" )
157
168
}
158
169
159
- if err := cluster .LoadImageArchive (ctx , imageArchive ); err != nil {
170
+ if err := cluster .LoadImageArchive (ctx , imageArchive , args ... ); err != nil {
160
171
return ctx , fmt .Errorf ("load image archive: %w" , err )
161
172
}
162
173
@@ -169,7 +180,7 @@ func LoadImageArchiveToCluster(name, imageArchive string) env.Func {
169
180
// in the provided destination.
170
181
func ExportClusterLogs (name , dest string ) env.Func {
171
182
return func (ctx context.Context , cfg * envconf.Config ) (context.Context , error ) {
172
- clusterVal := ctx .Value (clusterNameContextKey (name ))
183
+ clusterVal := ctx .Value (support . ClusterNameContextKey (name ))
173
184
if clusterVal == nil {
174
185
return ctx , fmt .Errorf ("export e2e provider cluster logs: context cluster is nil" )
175
186
}
@@ -186,3 +197,12 @@ func ExportClusterLogs(name, dest string) env.Func {
186
197
return ctx , nil
187
198
}
188
199
}
200
+
201
+ // PerformNodeOperation returns an EnvFunc that can be used to perform some node lifecycle operations.
202
+ // This can be used to add/remove/start/stop nodes in the cluster.
203
+ func PerformNodeOperation (clusterName string , action support.NodeOperation , node * support.Node , args ... string ) env.Func {
204
+ return func (ctx context.Context , cfg * envconf.Config ) (context.Context , error ) {
205
+ err := utils .PerformNodeLifecycleOperation (ctx , action , node , args ... )
206
+ return ctx , err
207
+ }
208
+ }
0 commit comments