@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- package helpers
17+ package toxiproxy
1818
1919import (
2020 "context"
@@ -29,13 +29,14 @@ import (
2929 toxiproxyapi "github.com/Shopify/toxiproxy/v2/client"
3030 . "github.com/onsi/gomega"
3131 corev1 "k8s.io/api/core/v1"
32+ "sigs.k8s.io/cluster-api-provider-cloudstack-staging/test/e2e/kubeconfig_helper"
3233 "sigs.k8s.io/cluster-api/test/framework"
3334 "sigs.k8s.io/cluster-api/test/framework/clusterctl"
3435 "sigs.k8s.io/cluster-api/test/framework/exec"
3536 "sigs.k8s.io/controller-runtime/pkg/client"
3637)
3738
38- func ToxiProxyServerExec (ctx context.Context ) error {
39+ func ServerExec (ctx context.Context ) error {
3940 execArgs := []string {"run" , "-d" , "--name=capc-e2e-toxiproxy" , "--net=host" , "--rm" , "ghcr.io/shopify/toxiproxy" }
4041 runCmd := exec .NewCommand (
4142 exec .WithCommand ("docker" ),
@@ -48,7 +49,7 @@ func ToxiProxyServerExec(ctx context.Context) error {
4849 return err
4950}
5051
51- func ToxiProxyServerKill (ctx context.Context ) error {
52+ func ServerKill (ctx context.Context ) error {
5253 execArgs := []string {"stop" , "capc-e2e-toxiproxy" }
5354 runCmd := exec .NewCommand (
5455 exec .WithCommand ("docker" ),
@@ -58,17 +59,17 @@ func ToxiProxyServerKill(ctx context.Context) error {
5859 return err
5960}
6061
61- type ToxiProxyContext struct {
62+ type Context struct {
6263 KubeconfigPath string
6364 Secret corev1.Secret
6465 ClusterProxy framework.ClusterProxy
6566 ToxiProxy * toxiproxyapi.Proxy
6667 ConfigPath string
6768}
6869
69- func SetupForToxiProxyTestingBootstrapCluster (bootstrapClusterProxy framework.ClusterProxy , clusterName string ) * ToxiProxyContext {
70+ func SetupForToxiProxyTestingBootstrapCluster (bootstrapClusterProxy framework.ClusterProxy , clusterName string ) * Context {
7071 // Read/parse the actual kubeconfig for the cluster
71- kubeConfig := NewKubeconfig ()
72+ kubeConfig := kubeconfig_helper . NewKubeconfig ()
7273 unproxiedKubeconfigPath := bootstrapClusterProxy .GetKubeconfigPath ()
7374 err := kubeConfig .Load (unproxiedKubeconfigPath )
7475 Expect (err ).To (BeNil ())
@@ -112,14 +113,14 @@ func SetupForToxiProxyTestingBootstrapCluster(bootstrapClusterProxy framework.Cl
112113 framework .WithMachineLogCollector (framework.DockerLogCollector {}),
113114 )
114115
115- return & ToxiProxyContext {
116+ return & Context {
116117 KubeconfigPath : toxiProxyKubeconfigPath ,
117118 ClusterProxy : toxiproxyBootstrapClusterProxy ,
118119 ToxiProxy : proxy ,
119120 }
120121}
121122
122- func TearDownToxiProxyBootstrap (toxiProxyContext * ToxiProxyContext ) {
123+ func TearDownToxiProxyBootstrap (toxiProxyContext * Context ) {
123124 // Tear down the proxy
124125 err := toxiProxyContext .ToxiProxy .Delete ()
125126 Expect (err ).To (BeNil ())
@@ -129,12 +130,12 @@ func TearDownToxiProxyBootstrap(toxiProxyContext *ToxiProxyContext) {
129130 Expect (err ).To (BeNil ())
130131}
131132
132- func (tp * ToxiProxyContext ) RemoveToxic (toxicName string ) {
133+ func (tp * Context ) RemoveToxic (toxicName string ) {
133134 err := tp .ToxiProxy .RemoveToxic (toxicName )
134135 Expect (err ).To (BeNil ())
135136}
136137
137- func (tp * ToxiProxyContext ) AddLatencyToxic (latencyMs int , jitterMs int , toxicity float32 , upstream bool ) string {
138+ func (tp * Context ) AddLatencyToxic (latencyMs int , jitterMs int , toxicity float32 , upstream bool ) string {
138139 stream := "downstream"
139140 if upstream == true {
140141 stream = "upstream"
@@ -150,15 +151,15 @@ func (tp *ToxiProxyContext) AddLatencyToxic(latencyMs int, jitterMs int, toxicit
150151 return toxicName
151152}
152153
153- func (tp * ToxiProxyContext ) Disable () {
154+ func (tp * Context ) Disable () {
154155 tp .ToxiProxy .Disable ()
155156}
156157
157- func (tp * ToxiProxyContext ) Enable () {
158+ func (tp * Context ) Enable () {
158159 tp .ToxiProxy .Enable ()
159160}
160161
161- func SetupForToxiProxyTestingACS (ctx context.Context , clusterName string , clusterProxy framework.ClusterProxy , e2eConfig * clusterctl.E2EConfig , configPath string ) * ToxiProxyContext {
162+ func SetupForToxiProxyTestingACS (ctx context.Context , clusterName string , clusterProxy framework.ClusterProxy , e2eConfig * clusterctl.E2EConfig , configPath string ) * Context {
162163 // Get the cloud-config secret that CAPC will use to access CloudStack
163164 fdEndpointSecretObjectKey := client.ObjectKey {
164165 Namespace : e2eConfig .GetVariable ("CLOUDSTACK_FD1_SECRET_NAMESPACE" ),
@@ -209,14 +210,14 @@ func SetupForToxiProxyTestingACS(ctx context.Context, clusterName string, cluste
209210 editConfigFile (newConfigFilePath , configPath , "CLOUDSTACK_FD1_SECRET_NAME" , toxiProxyFdEndpointSecret .Name )
210211
211212 // Return a context
212- return & ToxiProxyContext {
213+ return & Context {
213214 Secret : toxiProxyFdEndpointSecret ,
214215 ToxiProxy : proxy ,
215216 ConfigPath : newConfigFilePath ,
216217 }
217218}
218219
219- func TearDownToxiProxyACS (ctx context.Context , clusterProxy framework.ClusterProxy , toxiProxyContext * ToxiProxyContext ) {
220+ func TearDownToxiProxyACS (ctx context.Context , clusterProxy framework.ClusterProxy , toxiProxyContext * Context ) {
220221 // Tear down the proxy
221222 err := toxiProxyContext .ToxiProxy .Delete ()
222223 Expect (err ).To (BeNil ())
0 commit comments