From 8719f9846d2e8155cc57ee5d86e90932119ad936 Mon Sep 17 00:00:00 2001 From: Ravi Shankar Date: Fri, 6 Sep 2024 18:38:57 -0700 Subject: [PATCH] fix: GCP Config to use the config pkg similar to other configs --- cmd/main.go | 1 + config/config/gcpConfig.yaml | 3 ++ .../controller/cloud-control/suite_test.go | 7 +-- .../controller/cloud-resources/suite_test.go | 7 +-- pkg/kcp/provider/gcp/client/gcpConstants.go | 49 ++++++++++++++----- pkg/kcp/provider/gcp/client/provider.go | 3 +- pkg/kcp/provider/gcp/cloudclient/provider.go | 28 ----------- .../gcp/iprange/v1/checkGcpOperation.go | 5 +- .../gcp/iprange/v1/checkGcpOperation_test.go | 5 +- pkg/kcp/provider/gcp/iprange/v1/state.go | 10 +--- pkg/kcp/provider/gcp/iprange/v1/state_test.go | 4 +- .../provider/gcp/iprange/v1/syncAddress.go | 7 +-- .../gcp/iprange/v1/syncAddress_test.go | 9 ++-- .../gcp/iprange/v1/syncPsaConnection.go | 7 +-- .../gcp/iprange/v1/syncPsaConnection_test.go | 11 +++-- .../gcp/iprange/v2/checkGcpOperation.go | 5 +- .../gcp/iprange/v2/checkGcpOperation_test.go | 5 +- pkg/kcp/provider/gcp/iprange/v2/state.go | 10 +--- pkg/kcp/provider/gcp/iprange/v2/state_test.go | 4 +- .../provider/gcp/iprange/v2/syncAddress.go | 7 +-- .../gcp/iprange/v2/syncAddress_test.go | 9 ++-- .../gcp/iprange/v2/syncPsaConnection.go | 7 +-- .../gcp/iprange/v2/syncPsaConnection_test.go | 11 +++-- .../gcp/nfsinstance/checkGcpOperation.go | 3 +- .../gcp/nfsinstance/checkGcpOperation_test.go | 3 +- .../gcp/nfsinstance/loadNfsInstance.go | 3 +- pkg/kcp/provider/gcp/nfsinstance/state.go | 10 +--- .../gcp/nfsinstance/syncNfsInstance.go | 5 +- .../gcp/nfsinstance/syncNfsInstance_test.go | 13 ++--- pkg/kcp/provider/gcp/redisinstance/state.go | 10 +--- pkg/kcp/provider/gcp/vpcpeering/state.go | 10 +--- pkg/skr/backupschedule/state_test.go | 3 -- .../checkBackupOperation.go | 3 +- .../checkBackupOperation_test.go | 3 +- pkg/skr/gcpnfsvolumebackup/createNfsBackup.go | 5 +- .../createNfsBackup_test.go | 5 +- pkg/skr/gcpnfsvolumebackup/deleteNfsBackup.go | 3 +- .../deleteNfsBackup_test.go | 3 +- .../gcpnfsvolumebackup/loadGcpNfsVolume.go | 5 +- .../loadGcpNfsVolume_test.go | 5 +- pkg/skr/gcpnfsvolumebackup/loadNfsBackup.go | 3 +- .../gcpnfsvolumebackup/loadNfsBackup_test.go | 3 +- pkg/skr/gcpnfsvolumebackup/state.go | 4 -- pkg/skr/gcpnfsvolumebackup/state_test.go | 2 - pkg/skr/gcpnfsvolumebackup/updateStatus.go | 5 +- .../gcpnfsvolumebackup/updateStatus_test.go | 5 +- .../checkRestoreOperation.go | 3 +- .../checkRestoreOperation_test.go | 3 +- .../gcpnfsvolumerestore/loadGcpNfsVolume.go | 5 +- .../loadGcpNfsVolumeBackup.go | 5 +- .../loadGcpNfsVolumeBackup_test.go | 5 +- .../loadGcpNfsVolume_test.go | 5 +- .../gcpnfsvolumerestore/removeFinalizer.go | 3 +- pkg/skr/gcpnfsvolumerestore/runNfsRestore.go | 5 +- .../gcpnfsvolumerestore/runNfsRestore_test.go | 5 +- pkg/skr/gcpnfsvolumerestore/state.go | 4 -- pkg/skr/gcpnfsvolumerestore/state_test.go | 2 - pkg/testinfra/run.go | 8 +++ 58 files changed, 185 insertions(+), 196 deletions(-) create mode 100644 config/config/gcpConfig.yaml diff --git a/cmd/main.go b/cmd/main.go index c670d3f18..e2c68fa75 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -356,6 +356,7 @@ func loadConfig() config.Config { quota.InitConfig(cfg) skrruntimeconfig.InitConfig(cfg) scope.InitConfig(cfg) + gcpclient.InitConfig(cfg) cfg.Read() diff --git a/config/config/gcpConfig.yaml b/config/config/gcpConfig.yaml new file mode 100644 index 000000000..07cb22359 --- /dev/null +++ b/config/config/gcpConfig.yaml @@ -0,0 +1,3 @@ +retryWaitTime: 5s +operationWaitTime: 5s +apiTimeout: 8s diff --git a/internal/controller/cloud-control/suite_test.go b/internal/controller/cloud-control/suite_test.go index c0b816fbf..b9f971f64 100644 --- a/internal/controller/cloud-control/suite_test.go +++ b/internal/controller/cloud-control/suite_test.go @@ -68,12 +68,7 @@ var _ = BeforeSuite(func() { NotTo(HaveOccurred(), "failed creating namespace %s in Garden", infra.Garden().Namespace()) // Setup environment variables - env := abstractions.NewMockedEnvironment(map[string]string{ - "GCP_SA_JSON_KEY_PATH": "test", - "GCP_RETRY_WAIT_DURATION": "300ms", - "GCP_OPERATION_WAIT_DURATION": "300ms", - "GCP_API_TIMEOUT_DURATION": "300ms", - }) + env := abstractions.NewMockedEnvironment(map[string]string{}) // Setup controllers // Scope diff --git a/internal/controller/cloud-resources/suite_test.go b/internal/controller/cloud-resources/suite_test.go index ff295bed4..205b2663d 100644 --- a/internal/controller/cloud-resources/suite_test.go +++ b/internal/controller/cloud-resources/suite_test.go @@ -80,12 +80,7 @@ var _ = BeforeSuite(func() { quota.SkrQuota.Override(&cloudresourcesv1beta1.IpRange{}, infra.SKR().Scheme(), "", 1000) // Setup environment variables - env := abstractions.NewMockedEnvironment(map[string]string{ - "GCP_SA_JSON_KEY_PATH": "test", - "GCP_RETRY_WAIT_DURATION": "300ms", - "GCP_OPERATION_WAIT_DURATION": "300ms", - "GCP_API_TIMEOUT_DURATION": "300ms", - }) + env := abstractions.NewMockedEnvironment(map[string]string{}) testSetupLog := ctrl.Log.WithName("testSetup") diff --git a/pkg/kcp/provider/gcp/client/gcpConstants.go b/pkg/kcp/provider/gcp/client/gcpConstants.go index c35f15f6e..74f0e6c4b 100644 --- a/pkg/kcp/provider/gcp/client/gcpConstants.go +++ b/pkg/kcp/provider/gcp/client/gcpConstants.go @@ -2,10 +2,9 @@ package client import ( "fmt" + "github.com/kyma-project/cloud-manager/pkg/config" "time" - "github.com/kyma-project/cloud-manager/pkg/common/abstractions" - "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" ) @@ -22,22 +21,50 @@ const GcpRetryWaitTime = time.Second * 3 const GcpOperationWaitTime = time.Second * 5 const GcpApiTimeout = time.Second * 8 -type GcpConfig struct { +type GcpConfigStruct struct { GcpRetryWaitTime time.Duration GcpOperationWaitTime time.Duration GcpApiTimeout time.Duration + + //Config from files... + RetryWaitTime string `yaml:"retryWaitTime,omitempty" json:"retryWaitTime,omitempty"` + OperationWaitTime string `yaml:"operationWaitTime,omitempty" json:"operationWaitTime,omitempty"` + ApiTimeout string `yaml:"apiTimeout,omitempty" json:"apiTimeout,omitempty"` } -func GetGcpConfig(env abstractions.Environment) *GcpConfig { - return &GcpConfig{ - GcpRetryWaitTime: GetConfigDuration(env, "GCP_RETRY_WAIT_DURATION", GcpRetryWaitTime), - GcpOperationWaitTime: GetConfigDuration(env, "GCP_OPERATION_WAIT_DURATION", GcpOperationWaitTime), - GcpApiTimeout: GetConfigDuration(env, "GCP_API_TIMEOUT_DURATION", GcpApiTimeout), - } +func (c *GcpConfigStruct) AfterConfigLoaded() { + c.GcpRetryWaitTime = GetDuration(c.RetryWaitTime, GcpRetryWaitTime) + c.GcpOperationWaitTime = GetDuration(c.OperationWaitTime, GcpOperationWaitTime) + c.GcpApiTimeout = GetDuration(c.ApiTimeout, GcpApiTimeout) } -func GetConfigDuration(env abstractions.Environment, key string, defaultValue time.Duration) time.Duration { - duration, err := time.ParseDuration(env.Get(key)) +func InitConfig(cfg config.Config) { + cfg.Path( + "gcpConfig", + config.Path( + "retryWaitTime", + config.DefaultScalar("5s"), + config.SourceEnv("GCP_RETRY_WAIT_DURATION"), + ), + config.Path( + "operationWaitTime", + config.DefaultScalar("5s"), + config.SourceEnv("GCP_OPERATION_WAIT_DURATION"), + ), + config.Path( + "apiTimeout", + config.DefaultScalar("8s"), + config.SourceEnv("GCP_API_TIMEOUT_DURATION"), + ), + config.SourceFile("gcpclient.GcpConfig.yaml"), + config.Bind(GcpConfig), + ) +} + +var GcpConfig = &GcpConfigStruct{} + +func GetDuration(value string, defaultValue time.Duration) time.Duration { + duration, err := time.ParseDuration(value) if err != nil { return defaultValue } diff --git a/pkg/kcp/provider/gcp/client/provider.go b/pkg/kcp/provider/gcp/client/provider.go index e79c55de4..faea24786 100644 --- a/pkg/kcp/provider/gcp/client/provider.go +++ b/pkg/kcp/provider/gcp/client/provider.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "github.com/kyma-project/cloud-manager/pkg/common/abstractions" "github.com/kyma-project/cloud-manager/pkg/composed" "github.com/kyma-project/cloud-manager/pkg/metrics" "google.golang.org/api/cloudresourcemanager/v1" @@ -122,7 +121,7 @@ func newHttpClient(ctx context.Context, saJsonKeyPath string) (*http.Client, err return nil, fmt.Errorf("error obtaining GCP HTTP client: [%w]", err) } CheckGcpAuthentication(ctx, saJsonKeyPath) - client.Timeout = GetGcpConfig(abstractions.NewOSEnvironment()).GcpApiTimeout + client.Timeout = GcpConfig.GcpApiTimeout return client, nil } diff --git a/pkg/kcp/provider/gcp/cloudclient/provider.go b/pkg/kcp/provider/gcp/cloudclient/provider.go index cd976ea7f..e5c0f5432 100644 --- a/pkg/kcp/provider/gcp/cloudclient/provider.go +++ b/pkg/kcp/provider/gcp/cloudclient/provider.go @@ -2,34 +2,6 @@ package cloudclient import ( "context" - "github.com/kyma-project/cloud-manager/pkg/common/abstractions" - "time" ) type ClientProvider[T any] func(ctx context.Context, saJsonKeyPath string) (T, error) - -const GcpRetryWaitTime = time.Second * 3 -const GcpOperationWaitTime = time.Second * 5 -const GcpApiTimeout = time.Second * 3 - -type GcpConfig struct { - GcpRetryWaitTime time.Duration - GcpOperationWaitTime time.Duration - GcpApiTimeout time.Duration -} - -func GetGcpConfig(env abstractions.Environment) *GcpConfig { - return &GcpConfig{ - GcpRetryWaitTime: GetConfigDuration(env, "GCP_RETRY_WAIT_DURATION", GcpRetryWaitTime), - GcpOperationWaitTime: GetConfigDuration(env, "GCP_OPERATION_WAIT_DURATION", GcpOperationWaitTime), - GcpApiTimeout: GetConfigDuration(env, "GCP_API_TIMEOUT_DURATION", GcpApiTimeout), - } -} - -func GetConfigDuration(env abstractions.Environment, key string, defaultValue time.Duration) time.Duration { - duration, err := time.ParseDuration(env.Get(key)) - if err != nil { - return defaultValue - } - return duration -} diff --git a/pkg/kcp/provider/gcp/iprange/v1/checkGcpOperation.go b/pkg/kcp/provider/gcp/iprange/v1/checkGcpOperation.go index d48a1b8a6..8ba98a642 100644 --- a/pkg/kcp/provider/gcp/iprange/v1/checkGcpOperation.go +++ b/pkg/kcp/provider/gcp/iprange/v1/checkGcpOperation.go @@ -7,6 +7,7 @@ import ( "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "google.golang.org/api/googleapi" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -52,7 +53,7 @@ func checkGcpOperation(ctx context.Context, st composed.State) (error, context.C //Operation not completed yet.. requeue again. if op != nil && !op.Done { - return composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), nil + return composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), nil } //If not able to find the operation or it is completed, reset OpIdentifier. @@ -92,7 +93,7 @@ func checkGcpOperation(ctx context.Context, st composed.State) (error, context.C //Operation not completed yet.. requeue again. if op != nil && op.Status != "DONE" { - return composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), nil + return composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), nil } //If not able to find the operation or it is completed, reset OpIdentifier. diff --git a/pkg/kcp/provider/gcp/iprange/v1/checkGcpOperation_test.go b/pkg/kcp/provider/gcp/iprange/v1/checkGcpOperation_test.go index 4fb6c9f33..4938bb1fe 100644 --- a/pkg/kcp/provider/gcp/iprange/v1/checkGcpOperation_test.go +++ b/pkg/kcp/provider/gcp/iprange/v1/checkGcpOperation_test.go @@ -7,6 +7,7 @@ import ( cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "google.golang.org/api/compute/v1" @@ -205,7 +206,7 @@ func (suite *checkGcpOperationSuite) TestWhenSvcNwOperationNotComplete() { //Invoke the function under test err, resCtx := checkGcpOperation(ctx, state) assert.Nil(suite.T(), resCtx) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) } func (suite *checkGcpOperationSuite) TestWhenSvcNwOperationSuccessful() { @@ -414,7 +415,7 @@ func (suite *checkGcpOperationSuite) TestWhenComputeOperationNotComplete() { //Invoke the function under test err, resCtx := checkGcpOperation(ctx, state) assert.Nil(suite.T(), resCtx) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) } func (suite *checkGcpOperationSuite) TestWhenComputeOperationSuccessful() { diff --git a/pkg/kcp/provider/gcp/iprange/v1/state.go b/pkg/kcp/provider/gcp/iprange/v1/state.go index e328b02ff..be8e63ccd 100644 --- a/pkg/kcp/provider/gcp/iprange/v1/state.go +++ b/pkg/kcp/provider/gcp/iprange/v1/state.go @@ -29,9 +29,6 @@ type State struct { serviceNetworkingClient client3.ServiceNetworkingClient computeClient client3.ComputeClient - - //gcp config - gcpConfig *client2.GcpConfig } type StateFactory interface { @@ -42,7 +39,6 @@ type stateFactory struct { serviceNetworkingClientProvider client2.ClientProvider[client3.ServiceNetworkingClient] computeClientProvider client2.ClientProvider[client3.ComputeClient] env abstractions.Environment - gcpConfig *client2.GcpConfig } func NewStateFactory(serviceNetworkingClientProvider client2.ClientProvider[client3.ServiceNetworkingClient], computeClientProvider client2.ClientProvider[client3.ComputeClient], env abstractions.Environment) StateFactory { @@ -50,7 +46,6 @@ func NewStateFactory(serviceNetworkingClientProvider client2.ClientProvider[clie serviceNetworkingClientProvider: serviceNetworkingClientProvider, computeClientProvider: computeClientProvider, env: env, - gcpConfig: client2.GetGcpConfig(env), } } @@ -71,15 +66,14 @@ func (f *stateFactory) NewState(ctx context.Context, ipRangeState types.State) ( return nil, err } - return newState(ipRangeState, snc, cc, f.gcpConfig), nil + return newState(ipRangeState, snc, cc), nil } -func newState(ipRangeState types.State, snc client3.ServiceNetworkingClient, cc client3.ComputeClient, gcpConfig *client2.GcpConfig) *State { +func newState(ipRangeState types.State, snc client3.ServiceNetworkingClient, cc client3.ComputeClient) *State { return &State{ State: ipRangeState, serviceNetworkingClient: snc, computeClient: cc, - gcpConfig: gcpConfig, } } diff --git a/pkg/kcp/provider/gcp/iprange/v1/state_test.go b/pkg/kcp/provider/gcp/iprange/v1/state_test.go index 2e7583541..ac8d2de07 100644 --- a/pkg/kcp/provider/gcp/iprange/v1/state_test.go +++ b/pkg/kcp/provider/gcp/iprange/v1/state_test.go @@ -58,7 +58,6 @@ type testStateFactory struct { computeClientProvider client.ClientProvider[iprangeclient.ComputeClient] serviceNetworkingClientProvider client.ClientProvider[iprangeclient.ServiceNetworkingClient] fakeHttpServer *httptest.Server - gcpConfig *client.GcpConfig } func newTestStateFactory(fakeHttpServer *httptest.Server) (*testStateFactory, error) { @@ -90,7 +89,6 @@ func newTestStateFactory(fakeHttpServer *httptest.Server) (*testStateFactory, er computeClientProvider: computeClientProvider, serviceNetworkingClientProvider: svcNwClientProvider, fakeHttpServer: fakeHttpServer, - gcpConfig: client.GetGcpConfig(env), }, nil } @@ -127,7 +125,7 @@ func (f *testStateFactory) newStateWith(ctx context.Context, ipRange *cloudcontr }, }) - return newState(newTypesState(focalState), snc, cc, f.gcpConfig), nil + return newState(newTypesState(focalState), snc, cc), nil } diff --git a/pkg/kcp/provider/gcp/iprange/v1/syncAddress.go b/pkg/kcp/provider/gcp/iprange/v1/syncAddress.go index 3415a6cc3..452664f49 100644 --- a/pkg/kcp/provider/gcp/iprange/v1/syncAddress.go +++ b/pkg/kcp/provider/gcp/iprange/v1/syncAddress.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" @@ -45,15 +46,15 @@ func syncAddress(ctx context.Context, st composed.State) (error, context.Context Reason: v1beta1.ReasonGcpError, Message: err.Error(), }). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)). SuccessLogMsg(fmt.Sprintf("Error creating/deleting Address object in GCP :%s", err)). Run(ctx, state) } if operation != nil { ipRange.Status.OpIdentifier = operation.Name return composed.UpdateStatus(ipRange). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime)). Run(ctx, state) } - return composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime), nil + return composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime), nil } diff --git a/pkg/kcp/provider/gcp/iprange/v1/syncAddress_test.go b/pkg/kcp/provider/gcp/iprange/v1/syncAddress_test.go index e706ef7d3..6fe51dae2 100644 --- a/pkg/kcp/provider/gcp/iprange/v1/syncAddress_test.go +++ b/pkg/kcp/provider/gcp/iprange/v1/syncAddress_test.go @@ -7,6 +7,7 @@ import ( "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "google.golang.org/api/compute/v1" @@ -68,7 +69,7 @@ func (suite *syncAddressSuite) TestCreateSuccess() { //Invoke the function under test err, _ = syncAddress(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime), err) //Load updated object err = state.LoadObj(ctx) @@ -109,7 +110,7 @@ func (suite *syncAddressSuite) TestCreateFailure() { //Invoke the function under test err, _ = syncAddress(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) //Load updated object err = state.LoadObj(ctx) @@ -188,7 +189,7 @@ func (suite *syncAddressSuite) TestDeleteSuccess() { //Invoke the function under test err, _ = syncAddress(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime), err) //Load updated object err = state.LoadObj(ctx) @@ -238,7 +239,7 @@ func (suite *syncAddressSuite) TestDeleteFailure() { //Invoke the function under test err, _ = syncAddress(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) //Load updated object err = state.LoadObj(ctx) diff --git a/pkg/kcp/provider/gcp/iprange/v1/syncPsaConnection.go b/pkg/kcp/provider/gcp/iprange/v1/syncPsaConnection.go index 66a033caf..16ad06ea2 100644 --- a/pkg/kcp/provider/gcp/iprange/v1/syncPsaConnection.go +++ b/pkg/kcp/provider/gcp/iprange/v1/syncPsaConnection.go @@ -8,6 +8,7 @@ import ( "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "google.golang.org/api/servicenetworking/v1" ) @@ -42,15 +43,15 @@ func syncPsaConnection(ctx context.Context, st composed.State) (error, context.C Reason: v1beta1.ReasonGcpError, Message: err.Error(), }). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)). SuccessLogMsg(fmt.Sprintf("Error creating/deleting Service Connection object in GCP :%s", err)). Run(ctx, state) } if operation != nil { ipRange.Status.OpIdentifier = operation.Name return composed.UpdateStatus(ipRange). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime)). Run(ctx, state) } - return composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime), nil + return composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime), nil } diff --git a/pkg/kcp/provider/gcp/iprange/v1/syncPsaConnection_test.go b/pkg/kcp/provider/gcp/iprange/v1/syncPsaConnection_test.go index 55493d75d..5a98e6e0b 100644 --- a/pkg/kcp/provider/gcp/iprange/v1/syncPsaConnection_test.go +++ b/pkg/kcp/provider/gcp/iprange/v1/syncPsaConnection_test.go @@ -7,6 +7,7 @@ import ( "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "google.golang.org/api/cloudresourcemanager/v1" @@ -70,7 +71,7 @@ func (suite *syncPsaConnectionSuite) TestCreateSuccess() { //Invoke the function under test err, _ = syncPsaConnection(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime), err) //Load updated object err = state.LoadObj(ctx) @@ -120,7 +121,7 @@ func (suite *syncPsaConnectionSuite) TestCreateFailure() { //Invoke the function under test err, _ = syncPsaConnection(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) //Load updated object err = state.LoadObj(ctx) @@ -174,7 +175,7 @@ func (suite *syncPsaConnectionSuite) TestUpdate() { //Invoke the function under test err, _ = syncPsaConnection(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime), err) //Load updated object err = state.LoadObj(ctx) @@ -244,7 +245,7 @@ func (suite *syncPsaConnectionSuite) TestDeleteSuccess() { //Invoke the function under test err, _ = syncPsaConnection(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime), err) //Load updated object err = state.LoadObj(ctx) @@ -291,7 +292,7 @@ func (suite *syncPsaConnectionSuite) TestDeleteFailure() { //Invoke the function under test err, _ = syncPsaConnection(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) //Load updated object err = state.LoadObj(ctx) diff --git a/pkg/kcp/provider/gcp/iprange/v2/checkGcpOperation.go b/pkg/kcp/provider/gcp/iprange/v2/checkGcpOperation.go index bb0cd44a6..282ffdb4b 100644 --- a/pkg/kcp/provider/gcp/iprange/v2/checkGcpOperation.go +++ b/pkg/kcp/provider/gcp/iprange/v2/checkGcpOperation.go @@ -7,6 +7,7 @@ import ( "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "google.golang.org/api/googleapi" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -52,7 +53,7 @@ func checkGcpOperation(ctx context.Context, st composed.State) (error, context.C //Operation not completed yet.. requeue again. if op != nil && !op.Done { - return composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), nil + return composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), nil } //If not able to find the operation or it is completed, reset OpIdentifier. @@ -92,7 +93,7 @@ func checkGcpOperation(ctx context.Context, st composed.State) (error, context.C //Operation not completed yet.. requeue again. if op != nil && op.Status != "DONE" { - return composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), nil + return composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), nil } //If not able to find the operation or it is completed, reset OpIdentifier. diff --git a/pkg/kcp/provider/gcp/iprange/v2/checkGcpOperation_test.go b/pkg/kcp/provider/gcp/iprange/v2/checkGcpOperation_test.go index 306914c00..13ea37d7e 100644 --- a/pkg/kcp/provider/gcp/iprange/v2/checkGcpOperation_test.go +++ b/pkg/kcp/provider/gcp/iprange/v2/checkGcpOperation_test.go @@ -7,6 +7,7 @@ import ( cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "google.golang.org/api/compute/v1" @@ -205,7 +206,7 @@ func (suite *checkGcpOperationSuite) TestWhenSvcNwOperationNotComplete() { //Invoke the function under test err, resCtx := checkGcpOperation(ctx, state) assert.Nil(suite.T(), resCtx) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) } func (suite *checkGcpOperationSuite) TestWhenSvcNwOperationSuccessful() { @@ -414,7 +415,7 @@ func (suite *checkGcpOperationSuite) TestWhenComputeOperationNotComplete() { //Invoke the function under test err, resCtx := checkGcpOperation(ctx, state) assert.Nil(suite.T(), resCtx) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) } func (suite *checkGcpOperationSuite) TestWhenComputeOperationSuccessful() { diff --git a/pkg/kcp/provider/gcp/iprange/v2/state.go b/pkg/kcp/provider/gcp/iprange/v2/state.go index 1af0e1097..eec67aa59 100644 --- a/pkg/kcp/provider/gcp/iprange/v2/state.go +++ b/pkg/kcp/provider/gcp/iprange/v2/state.go @@ -29,9 +29,6 @@ type State struct { serviceNetworkingClient client3.ServiceNetworkingClient computeClient client3.ComputeClient - - //gcp config - gcpConfig *client2.GcpConfig } type StateFactory interface { @@ -42,7 +39,6 @@ type stateFactory struct { serviceNetworkingClientProvider client2.ClientProvider[client3.ServiceNetworkingClient] computeClientProvider client2.ClientProvider[client3.ComputeClient] env abstractions.Environment - gcpConfig *client2.GcpConfig } func NewStateFactory(serviceNetworkingClientProvider client2.ClientProvider[client3.ServiceNetworkingClient], computeClientProvider client2.ClientProvider[client3.ComputeClient], env abstractions.Environment) StateFactory { @@ -50,7 +46,6 @@ func NewStateFactory(serviceNetworkingClientProvider client2.ClientProvider[clie serviceNetworkingClientProvider: serviceNetworkingClientProvider, computeClientProvider: computeClientProvider, env: env, - gcpConfig: client2.GetGcpConfig(env), } } @@ -71,15 +66,14 @@ func (f *stateFactory) NewState(ctx context.Context, ipRangeState types.State) ( return nil, err } - return newState(ipRangeState, snc, cc, f.gcpConfig), nil + return newState(ipRangeState, snc, cc), nil } -func newState(ipRangeState types.State, snc client3.ServiceNetworkingClient, cc client3.ComputeClient, gcpConfig *client2.GcpConfig) *State { +func newState(ipRangeState types.State, snc client3.ServiceNetworkingClient, cc client3.ComputeClient) *State { return &State{ State: ipRangeState, serviceNetworkingClient: snc, computeClient: cc, - gcpConfig: gcpConfig, } } diff --git a/pkg/kcp/provider/gcp/iprange/v2/state_test.go b/pkg/kcp/provider/gcp/iprange/v2/state_test.go index 78af2168f..6aee46edc 100644 --- a/pkg/kcp/provider/gcp/iprange/v2/state_test.go +++ b/pkg/kcp/provider/gcp/iprange/v2/state_test.go @@ -59,7 +59,6 @@ type testStateFactory struct { computeClientProvider client.ClientProvider[iprangeclient.ComputeClient] serviceNetworkingClientProvider client.ClientProvider[iprangeclient.ServiceNetworkingClient] fakeHttpServer *httptest.Server - gcpConfig *client.GcpConfig } func newTestStateFactory(fakeHttpServer *httptest.Server) (*testStateFactory, error) { @@ -91,7 +90,6 @@ func newTestStateFactory(fakeHttpServer *httptest.Server) (*testStateFactory, er computeClientProvider: computeClientProvider, serviceNetworkingClientProvider: svcNwClientProvider, fakeHttpServer: fakeHttpServer, - gcpConfig: client.GetGcpConfig(env), }, nil } @@ -114,7 +112,7 @@ func (f *testStateFactory) newStateWithScope(ctx context.Context, ipRange *cloud focalState.SetScope(scope) - return newState(newTypesState(focalState), snc, cc, f.gcpConfig), nil + return newState(newTypesState(focalState), snc, cc), nil } diff --git a/pkg/kcp/provider/gcp/iprange/v2/syncAddress.go b/pkg/kcp/provider/gcp/iprange/v2/syncAddress.go index f66f5fd70..7f8c2d770 100644 --- a/pkg/kcp/provider/gcp/iprange/v2/syncAddress.go +++ b/pkg/kcp/provider/gcp/iprange/v2/syncAddress.go @@ -3,6 +3,7 @@ package v2 import ( "context" "fmt" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -46,15 +47,15 @@ func syncAddress(ctx context.Context, st composed.State) (error, context.Context Reason: v1beta1.ReasonGcpError, Message: err.Error(), }). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)). SuccessLogMsg(fmt.Sprintf("Error creating/deleting Address object in GCP :%s", err)). Run(ctx, state) } if operation != nil { ipRange.Status.OpIdentifier = operation.Name return composed.UpdateStatus(ipRange). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime)). Run(ctx, state) } - return composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime), nil + return composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime), nil } diff --git a/pkg/kcp/provider/gcp/iprange/v2/syncAddress_test.go b/pkg/kcp/provider/gcp/iprange/v2/syncAddress_test.go index f609af5da..e23da56d4 100644 --- a/pkg/kcp/provider/gcp/iprange/v2/syncAddress_test.go +++ b/pkg/kcp/provider/gcp/iprange/v2/syncAddress_test.go @@ -3,6 +3,7 @@ package v2 import ( "context" "encoding/json" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "net/http" "net/http/httptest" "strings" @@ -69,7 +70,7 @@ func (suite *syncAddressSuite) TestCreateSuccess() { //Invoke the function under test err, _ = syncAddress(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime), err) //Load updated object err = state.LoadObj(ctx) @@ -110,7 +111,7 @@ func (suite *syncAddressSuite) TestCreateFailure() { //Invoke the function under test err, _ = syncAddress(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) //Load updated object err = state.LoadObj(ctx) @@ -192,7 +193,7 @@ func (suite *syncAddressSuite) TestDeleteSuccess() { //Invoke the function under test err, _ = syncAddress(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime), err) //Load updated object err = state.LoadObj(ctx) @@ -245,7 +246,7 @@ func (suite *syncAddressSuite) TestDeleteFailure() { //Invoke the function under test err, _ = syncAddress(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) //Load updated object err = state.LoadObj(ctx) diff --git a/pkg/kcp/provider/gcp/iprange/v2/syncPsaConnection.go b/pkg/kcp/provider/gcp/iprange/v2/syncPsaConnection.go index 75c71aac7..9ac6f17ee 100644 --- a/pkg/kcp/provider/gcp/iprange/v2/syncPsaConnection.go +++ b/pkg/kcp/provider/gcp/iprange/v2/syncPsaConnection.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" @@ -46,15 +47,15 @@ func syncPsaConnection(ctx context.Context, st composed.State) (error, context.C Reason: v1beta1.ReasonGcpError, Message: err.Error(), }). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)). SuccessLogMsg(fmt.Sprintf("Error creating/deleting Service Connection object in GCP :%s", err)). Run(ctx, state) } if operation != nil { ipRange.Status.OpIdentifier = operation.Name return composed.UpdateStatus(ipRange). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime)). Run(ctx, state) } - return composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime), nil + return composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime), nil } diff --git a/pkg/kcp/provider/gcp/iprange/v2/syncPsaConnection_test.go b/pkg/kcp/provider/gcp/iprange/v2/syncPsaConnection_test.go index 801635a2a..3156f500a 100644 --- a/pkg/kcp/provider/gcp/iprange/v2/syncPsaConnection_test.go +++ b/pkg/kcp/provider/gcp/iprange/v2/syncPsaConnection_test.go @@ -7,6 +7,7 @@ import ( "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "google.golang.org/api/cloudresourcemanager/v1" @@ -70,7 +71,7 @@ func (suite *syncPsaConnectionSuite) TestCreateSuccess() { //Invoke the function under test err, _ = syncPsaConnection(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime), err) //Load updated object err = state.LoadObj(ctx) @@ -120,7 +121,7 @@ func (suite *syncPsaConnectionSuite) TestCreateFailure() { //Invoke the function under test err, _ = syncPsaConnection(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) //Load updated object err = state.LoadObj(ctx) @@ -175,7 +176,7 @@ func (suite *syncPsaConnectionSuite) TestUpdate() { //Invoke the function under test err, _ = syncPsaConnection(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime), err) //Load updated object err = state.LoadObj(ctx) @@ -245,7 +246,7 @@ func (suite *syncPsaConnectionSuite) TestDeleteSuccess() { //Invoke the function under test err, _ = syncPsaConnection(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime), err) //Load updated object err = state.LoadObj(ctx) @@ -292,7 +293,7 @@ func (suite *syncPsaConnectionSuite) TestDeleteFailure() { //Invoke the function under test err, _ = syncPsaConnection(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) //Load updated object err = state.LoadObj(ctx) diff --git a/pkg/kcp/provider/gcp/nfsinstance/checkGcpOperation.go b/pkg/kcp/provider/gcp/nfsinstance/checkGcpOperation.go index c3843c4ae..2bdd2e470 100644 --- a/pkg/kcp/provider/gcp/nfsinstance/checkGcpOperation.go +++ b/pkg/kcp/provider/gcp/nfsinstance/checkGcpOperation.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "google.golang.org/api/googleapi" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -50,7 +51,7 @@ func checkGcpOperation(ctx context.Context, st composed.State) (error, context.C //Operation not completed yet.. requeue again. if op != nil && !op.Done { - return composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), nil + return composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), nil } //If not able to find the operation or it is completed, reset OpIdentifier. diff --git a/pkg/kcp/provider/gcp/nfsinstance/checkGcpOperation_test.go b/pkg/kcp/provider/gcp/nfsinstance/checkGcpOperation_test.go index 312f83599..6b5410db8 100644 --- a/pkg/kcp/provider/gcp/nfsinstance/checkGcpOperation_test.go +++ b/pkg/kcp/provider/gcp/nfsinstance/checkGcpOperation_test.go @@ -6,6 +6,7 @@ import ( "github.com/go-logr/logr" "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "google.golang.org/api/file/v1" @@ -136,7 +137,7 @@ func (suite *checkGcpOperationSuite) TestCheckGcpOperationNotDoneOperation() { defer testState.FakeHttpServer.Close() err, resCtx := checkGcpOperation(ctx, testState.State) assert.Nil(suite.T(), resCtx) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(testState.gcpConfig.GcpRetryWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) } func (suite *checkGcpOperationSuite) TestCheckGcpOperationSuccessfulOperation() { diff --git a/pkg/kcp/provider/gcp/nfsinstance/loadNfsInstance.go b/pkg/kcp/provider/gcp/nfsinstance/loadNfsInstance.go index 9f1780e27..b4614e9d1 100644 --- a/pkg/kcp/provider/gcp/nfsinstance/loadNfsInstance.go +++ b/pkg/kcp/provider/gcp/nfsinstance/loadNfsInstance.go @@ -8,6 +8,7 @@ import ( "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "google.golang.org/api/googleapi" ) @@ -41,7 +42,7 @@ func loadNfsInstance(ctx context.Context, st composed.State) (error, context.Con Reason: v1beta1.ReasonGcpError, Message: "Error getting Filestore Instance from GCP", }). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)). SuccessLogMsg("Error getting Filestore Instance from GCP"). Run(ctx, state) } diff --git a/pkg/kcp/provider/gcp/nfsinstance/state.go b/pkg/kcp/provider/gcp/nfsinstance/state.go index 40eb65047..7e3942ffc 100644 --- a/pkg/kcp/provider/gcp/nfsinstance/state.go +++ b/pkg/kcp/provider/gcp/nfsinstance/state.go @@ -19,9 +19,6 @@ type State struct { validations []string fsInstance *file.Instance filestoreClient client.FilestoreClient - - //gcp config - gcpConfig *client2.GcpConfig } type StateFactory interface { @@ -31,14 +28,12 @@ type StateFactory interface { type stateFactory struct { filestoreClientProvider client2.ClientProvider[client.FilestoreClient] env abstractions.Environment - gcpConfig *client2.GcpConfig } func NewStateFactory(filestoreClientProvider client2.ClientProvider[client.FilestoreClient], env abstractions.Environment) StateFactory { return &stateFactory{ filestoreClientProvider: filestoreClientProvider, env: env, - gcpConfig: client2.GetGcpConfig(env), } } @@ -51,14 +46,13 @@ func (f *stateFactory) NewState(ctx context.Context, nfsInstanceState types.Stat if err != nil { return nil, err } - return newState(nfsInstanceState, fc, f.gcpConfig), nil + return newState(nfsInstanceState, fc), nil } -func newState(nfsInstanceState types.State, fc client.FilestoreClient, gcpConfig *client2.GcpConfig) *State { +func newState(nfsInstanceState types.State, fc client.FilestoreClient) *State { return &State{ State: nfsInstanceState, filestoreClient: fc, - gcpConfig: gcpConfig, } } diff --git a/pkg/kcp/provider/gcp/nfsinstance/syncNfsInstance.go b/pkg/kcp/provider/gcp/nfsinstance/syncNfsInstance.go index 70af89284..7ebcb99de 100644 --- a/pkg/kcp/provider/gcp/nfsinstance/syncNfsInstance.go +++ b/pkg/kcp/provider/gcp/nfsinstance/syncNfsInstance.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "strings" @@ -49,7 +50,7 @@ func syncNfsInstance(ctx context.Context, st composed.State) (error, context.Con Reason: v1beta1.ReasonGcpError, Message: err.Error(), }). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)). SuccessLogMsg(fmt.Sprintf("Error updating Filestore object in GCP :%s", err)). Run(ctx, state) } @@ -60,7 +61,7 @@ func syncNfsInstance(ctx context.Context, st composed.State) (error, context.Con } nfsInstance.Status.OpIdentifier = operation.Name return composed.UpdateStatus(nfsInstance). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime)). Run(ctx, state) } return nil, nil diff --git a/pkg/kcp/provider/gcp/nfsinstance/syncNfsInstance_test.go b/pkg/kcp/provider/gcp/nfsinstance/syncNfsInstance_test.go index 01c32daa8..358463a9a 100644 --- a/pkg/kcp/provider/gcp/nfsinstance/syncNfsInstance_test.go +++ b/pkg/kcp/provider/gcp/nfsinstance/syncNfsInstance_test.go @@ -7,6 +7,7 @@ import ( "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "google.golang.org/api/file/v1" @@ -66,7 +67,7 @@ func (suite *syncNfsInstanceSuite) TestSyncNfsInstanceAddSuccess() { defer testState.FakeHttpServer.Close() testState.operation = client.ADD err, _ = syncNfsInstance(ctx, testState.State) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(testState.gcpConfig.GcpOperationWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime), err) assert.NotNil(suite.T(), testState.State.ObjAsNfsInstance().Status.Id) assert.Equal(suite.T(), "create-instance-operation", testState.State.ObjAsNfsInstance().Status.OpIdentifier) @@ -113,7 +114,7 @@ func (suite *syncNfsInstanceSuite) TestSyncNfsInstanceAddError() { defer testState.FakeHttpServer.Close() testState.operation = client.ADD err, _ = syncNfsInstance(ctx, testState.State) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(testState.gcpConfig.GcpRetryWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) assert.Equal(suite.T(), "", testState.State.ObjAsNfsInstance().Status.Id) // check conditions assert.Len(suite.T(), testState.State.ObjAsNfsInstance().Status.Conditions, 1) @@ -169,7 +170,7 @@ func (suite *syncNfsInstanceSuite) TestSyncNfsInstancePatchSuccess() { testState.operation = client.MODIFY testState.updateMask = []string{"description"} err, _ = syncNfsInstance(ctx, testState.State) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(testState.gcpConfig.GcpOperationWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime), err) assert.NotNil(suite.T(), testState.State.ObjAsNfsInstance().Status.Id) assert.Equal(suite.T(), "patch-instance-operation", testState.State.ObjAsNfsInstance().Status.OpIdentifier) @@ -217,7 +218,7 @@ func (suite *syncNfsInstanceSuite) TestSyncNfsInstancePatchError() { testState.operation = client.MODIFY testState.updateMask = []string{"description"} err, _ = syncNfsInstance(ctx, testState.State) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(testState.gcpConfig.GcpRetryWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) assert.Equal(suite.T(), "", testState.State.ObjAsNfsInstance().Status.Id) // check conditions assert.Len(suite.T(), testState.State.ObjAsNfsInstance().Status.Conditions, 1) @@ -264,7 +265,7 @@ func (suite *syncNfsInstanceSuite) TestSyncNfsInstanceDeleteSuccess() { defer testState.FakeHttpServer.Close() testState.operation = client.DELETE err, _ = syncNfsInstance(ctx, testState.State) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(testState.gcpConfig.GcpOperationWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime), err) assert.Equal(suite.T(), "delete-instance-operation", testState.State.ObjAsNfsInstance().Status.OpIdentifier) updatedObject := &v1beta1.NfsInstance{} @@ -303,7 +304,7 @@ func (suite *syncNfsInstanceSuite) TestSyncNfsInstanceDeleteError() { defer testState.FakeHttpServer.Close() testState.operation = client.DELETE err, _ = syncNfsInstance(ctx, testState.State) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(testState.gcpConfig.GcpRetryWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) // check conditions assert.Len(suite.T(), testState.State.ObjAsNfsInstance().Status.Conditions, 1) assert.Equal(suite.T(), v1beta1.ConditionTypeError, testState.State.ObjAsNfsInstance().Status.Conditions[0].Type) diff --git a/pkg/kcp/provider/gcp/redisinstance/state.go b/pkg/kcp/provider/gcp/redisinstance/state.go index b234c2ec3..51ce38346 100644 --- a/pkg/kcp/provider/gcp/redisinstance/state.go +++ b/pkg/kcp/provider/gcp/redisinstance/state.go @@ -20,9 +20,6 @@ type State struct { memorystoreClient client.MemorystoreClient updateMask []string - - //gcp config - gcpConfig *gcpClient.GcpConfig } type StateFactory interface { @@ -32,14 +29,12 @@ type StateFactory interface { type stateFactory struct { memorystoreClientProvider gcpClient.ClientProvider[client.MemorystoreClient] env abstractions.Environment - gcpConfig *gcpClient.GcpConfig } func NewStateFactory(memorystoreClientProvider gcpClient.ClientProvider[client.MemorystoreClient], env abstractions.Environment) StateFactory { return &stateFactory{ memorystoreClientProvider: memorystoreClientProvider, env: env, - gcpConfig: gcpClient.GetGcpConfig(env), } } @@ -52,14 +47,13 @@ func (statefactory *stateFactory) NewState(ctx context.Context, redisInstanceSta if err != nil { return nil, err } - return newState(redisInstanceState, memorystoreClient, statefactory.gcpConfig), nil + return newState(redisInstanceState, memorystoreClient), nil } -func newState(redisInstanceState types.State, memorystoreClient client.MemorystoreClient, gcpConfig *gcpClient.GcpConfig) *State { +func newState(redisInstanceState types.State, memorystoreClient client.MemorystoreClient) *State { return &State{ State: redisInstanceState, memorystoreClient: memorystoreClient, - gcpConfig: gcpConfig, updateMask: []string{}, } } diff --git a/pkg/kcp/provider/gcp/vpcpeering/state.go b/pkg/kcp/provider/gcp/vpcpeering/state.go index 150f0b5e0..d955848f6 100644 --- a/pkg/kcp/provider/gcp/vpcpeering/state.go +++ b/pkg/kcp/provider/gcp/vpcpeering/state.go @@ -16,9 +16,6 @@ type State struct { client vpcpeeringclient.VpcPeeringClient provider gcpclient.ClientProvider[vpcpeeringclient.VpcPeeringClient] - //gcp config - gcpConfig *gcpclient.GcpConfig - remotePeeringName string remoteVpc string remoteProject string @@ -36,14 +33,12 @@ type StateFactory interface { type stateFactory struct { skrProvider gcpclient.ClientProvider[vpcpeeringclient.VpcPeeringClient] env abstractions.Environment - gcpConfig *gcpclient.GcpConfig } func NewStateFactory(skrProvider gcpclient.ClientProvider[vpcpeeringclient.VpcPeeringClient], env abstractions.Environment) StateFactory { return &stateFactory{ skrProvider: skrProvider, env: env, - gcpConfig: gcpclient.GetGcpConfig(env), } } @@ -57,18 +52,17 @@ func (f *stateFactory) NewState(ctx context.Context, vpcPeeringState vpcpeeringt return nil, err } - return newState(vpcPeeringState, c, f.skrProvider, f.gcpConfig), nil + return newState(vpcPeeringState, c, f.skrProvider), nil } func newState(vpcPeeringState vpcpeeringtypes.State, client vpcpeeringclient.VpcPeeringClient, provider gcpclient.ClientProvider[vpcpeeringclient.VpcPeeringClient], - gcpConfig *gcpclient.GcpConfig) *State { +) *State { return &State{ State: vpcPeeringState, client: client, provider: provider, - gcpConfig: gcpConfig, remotePeeringName: vpcPeeringState.ObjAsVpcPeering().Spec.VpcPeering.Gcp.RemotePeeringName, remoteVpc: vpcPeeringState.ObjAsVpcPeering().Spec.VpcPeering.Gcp.RemoteVpc, remoteProject: vpcPeeringState.ObjAsVpcPeering().Spec.VpcPeering.Gcp.RemoteProject, diff --git a/pkg/skr/backupschedule/state_test.go b/pkg/skr/backupschedule/state_test.go index a5d7d34a4..b9c229503 100644 --- a/pkg/skr/backupschedule/state_test.go +++ b/pkg/skr/backupschedule/state_test.go @@ -6,7 +6,6 @@ import ( cloudresourcesv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" "github.com/kyma-project/cloud-manager/pkg/common/abstractions" "github.com/kyma-project/cloud-manager/pkg/composed" - gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -166,7 +165,6 @@ type testStateFactory struct { skrCluster composed.StateCluster kcpCluster composed.StateCluster env abstractions.Environment - gcpConfig *gcpclient.GcpConfig } func newTestStateFactoryWithObj(object client.Object) (*testStateFactory, error) { @@ -203,7 +201,6 @@ func newTestStateFactoryWithObj(object client.Object) (*testStateFactory, error) skrCluster: skrCluster, kcpCluster: kcpCluster, env: env, - gcpConfig: gcpclient.GetGcpConfig(env), }, nil } diff --git a/pkg/skr/gcpnfsvolumebackup/checkBackupOperation.go b/pkg/skr/gcpnfsvolumebackup/checkBackupOperation.go index 93ae101eb..5629dc813 100644 --- a/pkg/skr/gcpnfsvolumebackup/checkBackupOperation.go +++ b/pkg/skr/gcpnfsvolumebackup/checkBackupOperation.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "google.golang.org/api/googleapi" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -52,7 +53,7 @@ func checkBackupOperation(ctx context.Context, st composed.State) (error, contex //Operation not completed yet.. requeue again. if op != nil && !op.Done { - return composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), nil + return composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), nil } //If not able to find the operation or it is completed, reset OpIdentifier. diff --git a/pkg/skr/gcpnfsvolumebackup/checkBackupOperation_test.go b/pkg/skr/gcpnfsvolumebackup/checkBackupOperation_test.go index 47bd9c5f2..340486acc 100644 --- a/pkg/skr/gcpnfsvolumebackup/checkBackupOperation_test.go +++ b/pkg/skr/gcpnfsvolumebackup/checkBackupOperation_test.go @@ -6,6 +6,7 @@ import ( cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "google.golang.org/api/file/v1" @@ -144,7 +145,7 @@ func (suite *checkBackupOperationSuite) TestCheckBackupOperationNotCompleted() { assert.Nil(suite.T(), err) state.Scope = &scope err, ctx = checkBackupOperation(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) fromK8s := &v1beta1.GcpNfsVolumeBackup{} err = factory.skrCluster.K8sClient().Get(ctx, types.NamespacedName{Name: obj.Name, diff --git a/pkg/skr/gcpnfsvolumebackup/createNfsBackup.go b/pkg/skr/gcpnfsvolumebackup/createNfsBackup.go index 509f410c6..04f2abd20 100644 --- a/pkg/skr/gcpnfsvolumebackup/createNfsBackup.go +++ b/pkg/skr/gcpnfsvolumebackup/createNfsBackup.go @@ -9,6 +9,7 @@ import ( cloudresourcesv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "google.golang.org/api/file/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "strings" @@ -82,7 +83,7 @@ func createNfsBackup(ctx context.Context, st composed.State) (error, context.Con Reason: cloudcontrolv1beta1.ReasonGcpError, Message: err.Error(), }). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)). SuccessLogMsg(fmt.Sprintf("Error creating Filestore backup in GCP :%s", err)). Run(ctx, state) } @@ -92,7 +93,7 @@ func createNfsBackup(ctx context.Context, st composed.State) (error, context.Con return composed.PatchStatus(backup). SetExclusiveConditions(). // Give some time for backup to get created. - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)). Run(ctx, state) } diff --git a/pkg/skr/gcpnfsvolumebackup/createNfsBackup_test.go b/pkg/skr/gcpnfsvolumebackup/createNfsBackup_test.go index 2b6651f28..3a92da05b 100644 --- a/pkg/skr/gcpnfsvolumebackup/createNfsBackup_test.go +++ b/pkg/skr/gcpnfsvolumebackup/createNfsBackup_test.go @@ -8,6 +8,7 @@ import ( cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "google.golang.org/api/file/v1" @@ -110,7 +111,7 @@ func (suite *createNfsBackupSuite) TestWhenCreateBackupReturnsError() { err, _ctx := createNfsBackup(ctx, state) //validate expected return values - suite.Equal(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + suite.Equal(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) suite.NotNil(_ctx) fromK8s := &v1beta1.GcpNfsVolumeBackup{} @@ -220,7 +221,7 @@ func (suite *createNfsBackupSuite) TestWhenCreateBackupSuccessful() { err, _ctx := createNfsBackup(ctx, state) //validate expected return values - suite.Equal(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + suite.Equal(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) suite.NotNil(_ctx) fromK8s := &v1beta1.GcpNfsVolumeBackup{} diff --git a/pkg/skr/gcpnfsvolumebackup/deleteNfsBackup.go b/pkg/skr/gcpnfsvolumebackup/deleteNfsBackup.go index 9c5465ea7..cb3e0e933 100644 --- a/pkg/skr/gcpnfsvolumebackup/deleteNfsBackup.go +++ b/pkg/skr/gcpnfsvolumebackup/deleteNfsBackup.go @@ -6,6 +6,7 @@ import ( cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" cloudresourcesv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -49,7 +50,7 @@ func deleteNfsBackup(ctx context.Context, st composed.State) (error, context.Con Reason: cloudcontrolv1beta1.ReasonGcpError, Message: err.Error(), }). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)). SuccessLogMsg(fmt.Sprintf("Error deleting File backup object in GCP :%s", err)). Run(ctx, state) } diff --git a/pkg/skr/gcpnfsvolumebackup/deleteNfsBackup_test.go b/pkg/skr/gcpnfsvolumebackup/deleteNfsBackup_test.go index c5549b125..2f8f07d22 100644 --- a/pkg/skr/gcpnfsvolumebackup/deleteNfsBackup_test.go +++ b/pkg/skr/gcpnfsvolumebackup/deleteNfsBackup_test.go @@ -7,6 +7,7 @@ import ( cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "google.golang.org/api/file/v1" @@ -110,7 +111,7 @@ func (suite *deleteNfsBackupSuite) TestWhenDeleteBackupReturnsError() { err, _ctx := deleteNfsBackup(ctx, state) //validate expected return values - suite.Equal(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + suite.Equal(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) suite.NotNil(_ctx) fromK8s := &v1beta1.GcpNfsVolumeBackup{} diff --git a/pkg/skr/gcpnfsvolumebackup/loadGcpNfsVolume.go b/pkg/skr/gcpnfsvolumebackup/loadGcpNfsVolume.go index ede7bebb0..62707c18e 100644 --- a/pkg/skr/gcpnfsvolumebackup/loadGcpNfsVolume.go +++ b/pkg/skr/gcpnfsvolumebackup/loadGcpNfsVolume.go @@ -5,6 +5,7 @@ import ( cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" cloudresourcesv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -39,7 +40,7 @@ func loadGcpNfsVolume(ctx context.Context, st composed.State) (error, context.Co Reason: cloudcontrolv1beta1.ReasonGcpError, Message: "Error loading GcpNfsVolume", }). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)). SuccessLogMsg("Error getting GcpNfsVolume"). Run(ctx, state) } @@ -58,7 +59,7 @@ func loadGcpNfsVolume(ctx context.Context, st composed.State) (error, context.Co Reason: cloudcontrolv1beta1.ReasonGcpError, Message: "Error loading GcpNfsVolume", }). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)). SuccessLogMsg("Error getting GcpNfsVolume"). Run(ctx, state) } diff --git a/pkg/skr/gcpnfsvolumebackup/loadGcpNfsVolume_test.go b/pkg/skr/gcpnfsvolumebackup/loadGcpNfsVolume_test.go index e02d2c4c8..30d98403b 100644 --- a/pkg/skr/gcpnfsvolumebackup/loadGcpNfsVolume_test.go +++ b/pkg/skr/gcpnfsvolumebackup/loadGcpNfsVolume_test.go @@ -5,6 +5,7 @@ import ( cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "google.golang.org/api/file/v1" @@ -90,7 +91,7 @@ func (suite *loadGcpNfsVolumeSuite) TestVolumeNotFound() { err, _ctx := loadGcpNfsVolume(ctx, state) //validate expected return values - suite.Equal(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + suite.Equal(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) suite.Equal(ctx, _ctx) } @@ -118,7 +119,7 @@ func (suite *loadGcpNfsVolumeSuite) TestVolumeNotReady() { err, _ = loadGcpNfsVolume(ctx, state) //validate expected return values - suite.Equal(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + suite.Equal(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) fromK8s := &v1beta1.GcpNfsVolumeBackup{} err = factory.skrCluster.K8sClient().Get(ctx, types.NamespacedName{Name: gcpNfsVolumeBackup.Name, diff --git a/pkg/skr/gcpnfsvolumebackup/loadNfsBackup.go b/pkg/skr/gcpnfsvolumebackup/loadNfsBackup.go index 690c847e6..ebc3a90f4 100644 --- a/pkg/skr/gcpnfsvolumebackup/loadNfsBackup.go +++ b/pkg/skr/gcpnfsvolumebackup/loadNfsBackup.go @@ -9,6 +9,7 @@ import ( cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "google.golang.org/api/googleapi" ) @@ -48,7 +49,7 @@ func loadNfsBackup(ctx context.Context, st composed.State) (error, context.Conte Reason: cloudcontrolv1beta1.ReasonGcpError, Message: err.Error(), }). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)). SuccessLogMsg(fmt.Sprintf("Error getting GCP backup : %s", err)). Run(ctx, state) } diff --git a/pkg/skr/gcpnfsvolumebackup/loadNfsBackup_test.go b/pkg/skr/gcpnfsvolumebackup/loadNfsBackup_test.go index 0661014bb..865521f95 100644 --- a/pkg/skr/gcpnfsvolumebackup/loadNfsBackup_test.go +++ b/pkg/skr/gcpnfsvolumebackup/loadNfsBackup_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "net/http" @@ -91,7 +92,7 @@ func (suite *loadGcpNfsVolumeBackupSuite) TestVolumeBackupOtherError() { err, _ctx := loadNfsBackup(ctx, state) //validate expected return values - suite.Equal(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + suite.Equal(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) suite.Equal(ctx, _ctx) } diff --git a/pkg/skr/gcpnfsvolumebackup/state.go b/pkg/skr/gcpnfsvolumebackup/state.go index fdf46abd4..3af635c96 100644 --- a/pkg/skr/gcpnfsvolumebackup/state.go +++ b/pkg/skr/gcpnfsvolumebackup/state.go @@ -24,7 +24,6 @@ type State struct { fileBackup *file.Backup fileBackupClient client.FileBackupClient - gcpConfig *client2.GcpConfig } type StateFactory interface { @@ -40,7 +39,6 @@ func NewStateFactory(kymaRef klog.ObjectRef, kcpCluster composed.StateCluster, s skrCluster: skrCluster, fileBackupClientProvider: fileBackupClientProvider, env: env, - gcpConfig: client2.GetGcpConfig(env), } } @@ -50,7 +48,6 @@ type stateFactory struct { skrCluster composed.StateCluster fileBackupClientProvider client2.ClientProvider[client.FileBackupClient] env abstractions.Environment - gcpConfig *client2.GcpConfig } func (f *stateFactory) NewState(ctx context.Context, baseState composed.State) (*State, error) { @@ -67,7 +64,6 @@ func (f *stateFactory) NewState(ctx context.Context, baseState composed.State) ( KcpCluster: f.kcpCluster, SkrCluster: f.skrCluster, fileBackupClient: fbc, - gcpConfig: f.gcpConfig, }, nil } diff --git a/pkg/skr/gcpnfsvolumebackup/state_test.go b/pkg/skr/gcpnfsvolumebackup/state_test.go index a98358de3..017aac006 100644 --- a/pkg/skr/gcpnfsvolumebackup/state_test.go +++ b/pkg/skr/gcpnfsvolumebackup/state_test.go @@ -139,7 +139,6 @@ type testStateFactory struct { kcpCluster composed.StateCluster fileBackupClientProvider client.ClientProvider[client2.FileBackupClient] env abstractions.Environment - gcpConfig *client.GcpConfig fakeHttpServer *httptest.Server } @@ -189,7 +188,6 @@ func newTestStateFactoryWithObj(fakeHttpServer *httptest.Server, gcpNfsVolumeBac kcpCluster: kcpCluster, fileBackupClientProvider: nfsBackupClient, env: env, - gcpConfig: client.GetGcpConfig(env), fakeHttpServer: fakeHttpServer, }, nil diff --git a/pkg/skr/gcpnfsvolumebackup/updateStatus.go b/pkg/skr/gcpnfsvolumebackup/updateStatus.go index c9d02c05e..2e34968f4 100644 --- a/pkg/skr/gcpnfsvolumebackup/updateStatus.go +++ b/pkg/skr/gcpnfsvolumebackup/updateStatus.go @@ -4,6 +4,7 @@ import ( "context" cloudresourcesv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -21,7 +22,7 @@ func updateStatus(ctx context.Context, st composed.State) (error, context.Contex if state.fileBackup == nil { return composed.StopAndForget, nil } else { - return composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), nil + return composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), nil } } @@ -30,7 +31,7 @@ func updateStatus(ctx context.Context, st composed.State) (error, context.Contex // Requeue to check the status of the backup if state.fileBackup == nil || state.fileBackup.State != "READY" { - return composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), nil + return composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), nil } //If file backup is ready, update the status of the backup diff --git a/pkg/skr/gcpnfsvolumebackup/updateStatus_test.go b/pkg/skr/gcpnfsvolumebackup/updateStatus_test.go index 823b32da4..349498299 100644 --- a/pkg/skr/gcpnfsvolumebackup/updateStatus_test.go +++ b/pkg/skr/gcpnfsvolumebackup/updateStatus_test.go @@ -6,6 +6,7 @@ import ( cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "google.golang.org/api/file/v1" @@ -44,7 +45,7 @@ func (suite *updateStatusSuite) TestDeletingBackupExists() { err, _ctx := updateStatus(ctx, state) //validate expected return values - suite.Equal(err, composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime)) + suite.Equal(err, composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)) suite.Nil(_ctx) } @@ -165,7 +166,7 @@ func (suite *updateStatusSuite) TestNotReadyAndBackupNotReady() { err, _ctx := updateStatus(ctx, state) //validate expected return values - suite.Equal(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + suite.Equal(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) suite.Nil(_ctx) } diff --git a/pkg/skr/gcpnfsvolumerestore/checkRestoreOperation.go b/pkg/skr/gcpnfsvolumerestore/checkRestoreOperation.go index 0aaf76bb4..0baf3ebd7 100644 --- a/pkg/skr/gcpnfsvolumerestore/checkRestoreOperation.go +++ b/pkg/skr/gcpnfsvolumerestore/checkRestoreOperation.go @@ -10,6 +10,7 @@ import ( cloudControl "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" ) func checkRestoreOperation(ctx context.Context, st composed.State) (error, context.Context) { @@ -53,7 +54,7 @@ func checkRestoreOperation(ctx context.Context, st composed.State) (error, conte //Operation not completed yet.. requeue again. if op != nil && !op.Done { - return composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), nil + return composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), nil } //If not able to find the operation or it is completed, reset OpIdentifier. diff --git a/pkg/skr/gcpnfsvolumerestore/checkRestoreOperation_test.go b/pkg/skr/gcpnfsvolumerestore/checkRestoreOperation_test.go index cc74239bd..5d5989a01 100644 --- a/pkg/skr/gcpnfsvolumerestore/checkRestoreOperation_test.go +++ b/pkg/skr/gcpnfsvolumerestore/checkRestoreOperation_test.go @@ -6,6 +6,7 @@ import ( cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "google.golang.org/api/file/v1" @@ -142,7 +143,7 @@ func (suite *checkRestoreOperationSuite) TestCheckRestoreOperationNotCompleted() assert.Nil(suite.T(), err) state.Scope = &scope err, ctx = checkRestoreOperation(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) fromK8s := &v1beta1.GcpNfsVolumeRestore{} err = factory.skrCluster.K8sClient().Get(ctx, types.NamespacedName{Name: obj.Name, diff --git a/pkg/skr/gcpnfsvolumerestore/loadGcpNfsVolume.go b/pkg/skr/gcpnfsvolumerestore/loadGcpNfsVolume.go index 8211bffd4..63980a31e 100644 --- a/pkg/skr/gcpnfsvolumerestore/loadGcpNfsVolume.go +++ b/pkg/skr/gcpnfsvolumerestore/loadGcpNfsVolume.go @@ -9,6 +9,7 @@ import ( cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" ) func loadGcpNfsVolume(ctx context.Context, st composed.State) (error, context.Context) { @@ -39,7 +40,7 @@ func loadGcpNfsVolume(ctx context.Context, st composed.State) (error, context.Co Reason: cloudresourcesv1beta1.ConditionReasonMissingNfsVolume, Message: "Error loading GcpNfsVolume", }). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)). SuccessLogMsg("Error getting GcpNfsVolume"). Run(ctx, state) } @@ -58,7 +59,7 @@ func loadGcpNfsVolume(ctx context.Context, st composed.State) (error, context.Co Reason: cloudcontrolv1beta1.ReasonGcpError, Message: "Error loading GcpNfsVolume", }). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)). SuccessLogMsg("Error getting GcpNfsVolume"). Run(ctx, state) } diff --git a/pkg/skr/gcpnfsvolumerestore/loadGcpNfsVolumeBackup.go b/pkg/skr/gcpnfsvolumerestore/loadGcpNfsVolumeBackup.go index dd92ae393..3ab49c16a 100644 --- a/pkg/skr/gcpnfsvolumerestore/loadGcpNfsVolumeBackup.go +++ b/pkg/skr/gcpnfsvolumerestore/loadGcpNfsVolumeBackup.go @@ -8,6 +8,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" ) func loadGcpNfsVolumeBackup(ctx context.Context, st composed.State) (error, context.Context) { @@ -43,7 +44,7 @@ func loadGcpNfsVolumeBackup(ctx context.Context, st composed.State) (error, cont Reason: cloudresourcesv1beta1.ConditionReasonMissingNfsVolumeBackup, Message: "Error loading GcpNfsVolumeBackup", }). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)). SuccessLogMsg("Error getting GcpNfsVolumeBackup"). Run(ctx, state) } @@ -62,7 +63,7 @@ func loadGcpNfsVolumeBackup(ctx context.Context, st composed.State) (error, cont Reason: cloudresourcesv1beta1.ConditionReasonNfsVolumeBackupNotReady, Message: "GcpNfsVolumeBackup is not ready", }). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)). SuccessLogMsg("Error loading GcpNfsVolumeBackup"). Run(ctx, state) } diff --git a/pkg/skr/gcpnfsvolumerestore/loadGcpNfsVolumeBackup_test.go b/pkg/skr/gcpnfsvolumerestore/loadGcpNfsVolumeBackup_test.go index 14cc003cc..3382a7092 100644 --- a/pkg/skr/gcpnfsvolumerestore/loadGcpNfsVolumeBackup_test.go +++ b/pkg/skr/gcpnfsvolumerestore/loadGcpNfsVolumeBackup_test.go @@ -5,6 +5,7 @@ import ( cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -42,7 +43,7 @@ func (suite *loadGcpNfsVolumeBackupSuite) TestVolumeBackupNotFound() { err, _ctx := loadGcpNfsVolumeBackup(ctx, state) //validate expected return values - suite.Equal(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + suite.Equal(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) suite.Equal(ctx, _ctx) } @@ -68,7 +69,7 @@ func (suite *loadGcpNfsVolumeBackupSuite) TestVolumeBackupNotReady() { err, _ = loadGcpNfsVolumeBackup(ctx, state) //validate expected return values - suite.Equal(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + suite.Equal(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) fromK8s := &v1beta1.GcpNfsVolumeRestore{} err = factory.skrCluster.K8sClient().Get(ctx, types.NamespacedName{Name: gcpNfsVolumeRestore.Name, diff --git a/pkg/skr/gcpnfsvolumerestore/loadGcpNfsVolume_test.go b/pkg/skr/gcpnfsvolumerestore/loadGcpNfsVolume_test.go index 78af7327b..97b22c64c 100644 --- a/pkg/skr/gcpnfsvolumerestore/loadGcpNfsVolume_test.go +++ b/pkg/skr/gcpnfsvolumerestore/loadGcpNfsVolume_test.go @@ -5,6 +5,7 @@ import ( cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1" "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -42,7 +43,7 @@ func (suite *loadGcpNfsVolumeSuite) TestVolumeNotFound() { err, _ctx := loadGcpNfsVolume(ctx, state) //validate expected return values - suite.Equal(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + suite.Equal(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) suite.Equal(ctx, _ctx) } @@ -69,7 +70,7 @@ func (suite *loadGcpNfsVolumeSuite) TestVolumeNotReady() { err, _ = loadGcpNfsVolume(ctx, state) //validate expected return values - suite.Equal(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + suite.Equal(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) fromK8s := &v1beta1.GcpNfsVolumeRestore{} err = factory.skrCluster.K8sClient().Get(ctx, types.NamespacedName{Name: gcpNfsVolumeRestore.Name, diff --git a/pkg/skr/gcpnfsvolumerestore/removeFinalizer.go b/pkg/skr/gcpnfsvolumerestore/removeFinalizer.go index d5de0aedb..677bcaa31 100644 --- a/pkg/skr/gcpnfsvolumerestore/removeFinalizer.go +++ b/pkg/skr/gcpnfsvolumerestore/removeFinalizer.go @@ -4,6 +4,7 @@ import ( "context" cloudresourcesv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" ) @@ -25,7 +26,7 @@ func removeFinalizer(ctx context.Context, st composed.State) (error, context.Con Reason: cloudresourcesv1beta1.ConditionReasonNfsRestoreInProgress, Message: "In progress restore cannot be deleted", }). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)). Run(ctx, state) } diff --git a/pkg/skr/gcpnfsvolumerestore/runNfsRestore.go b/pkg/skr/gcpnfsvolumerestore/runNfsRestore.go index c5077b2e6..ccba26b1c 100644 --- a/pkg/skr/gcpnfsvolumerestore/runNfsRestore.go +++ b/pkg/skr/gcpnfsvolumerestore/runNfsRestore.go @@ -7,6 +7,7 @@ import ( cloudresourcesv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -56,7 +57,7 @@ func runNfsRestore(ctx context.Context, st composed.State) (error, context.Conte Reason: cloudcontrolv1beta1.ReasonGcpError, Message: err.Error(), }). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime)). SuccessLogMsg(fmt.Sprintf("Error submitting Filestore restore request in GCP :%s. Retrying", err)). Run(ctx, state) } @@ -64,7 +65,7 @@ func runNfsRestore(ctx context.Context, st composed.State) (error, context.Conte restore.Status.OpIdentifier = operation.Name restore.Status.State = cloudresourcesv1beta1.JobStateInProgress return composed.PatchStatus(restore). - SuccessError(composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime)). + SuccessError(composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime)). Run(ctx, state) } return nil, nil diff --git a/pkg/skr/gcpnfsvolumerestore/runNfsRestore_test.go b/pkg/skr/gcpnfsvolumerestore/runNfsRestore_test.go index 18be37767..525b69276 100644 --- a/pkg/skr/gcpnfsvolumerestore/runNfsRestore_test.go +++ b/pkg/skr/gcpnfsvolumerestore/runNfsRestore_test.go @@ -5,6 +5,7 @@ import ( "github.com/go-logr/logr" cloudresourcesv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-resources/v1beta1" "github.com/kyma-project/cloud-manager/pkg/composed" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "google.golang.org/api/file/v1" @@ -112,7 +113,7 @@ func (suite *runNfsRestoreSuite) TestRunNfsRestoreSubmitFailed() { state.GcpNfsVolume = gcpNfsVolume.DeepCopy() assert.Nil(suite.T(), err) err, _ctx := runNfsRestore(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpRetryWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpRetryWaitTime), err) assert.Equal(suite.T(), ctx, _ctx) } @@ -153,7 +154,7 @@ func (suite *runNfsRestoreSuite) TestRunNfsRestoreSubmitted() { state.GcpNfsVolume = gcpNfsVolume.DeepCopy() assert.Nil(suite.T(), err) err, _ctx := runNfsRestore(ctx, state) - assert.Equal(suite.T(), composed.StopWithRequeueDelay(state.gcpConfig.GcpOperationWaitTime), err) + assert.Equal(suite.T(), composed.StopWithRequeueDelay(gcpclient.GcpConfig.GcpOperationWaitTime), err) assert.Equal(suite.T(), ctx, _ctx) fromK8s := &cloudresourcesv1beta1.GcpNfsVolumeRestore{} err = factory.skrCluster.K8sClient().Get(ctx, diff --git a/pkg/skr/gcpnfsvolumerestore/state.go b/pkg/skr/gcpnfsvolumerestore/state.go index 66c82b420..01c38e272 100644 --- a/pkg/skr/gcpnfsvolumerestore/state.go +++ b/pkg/skr/gcpnfsvolumerestore/state.go @@ -22,7 +22,6 @@ type State struct { GcpNfsVolumeBackup *cloudresourcesv1beta1.GcpNfsVolumeBackup fileRestoreClient client.FileRestoreClient - gcpConfig *client2.GcpConfig } type StateFactory interface { @@ -38,7 +37,6 @@ func NewStateFactory(kymaRef klog.ObjectRef, kcpCluster composed.StateCluster, s skrCluster: skrCluster, fileRestoreClientProvider: fileRestoreClientProvider, env: env, - gcpConfig: client2.GetGcpConfig(env), } } @@ -48,7 +46,6 @@ type stateFactory struct { skrCluster composed.StateCluster fileRestoreClientProvider client2.ClientProvider[client.FileRestoreClient] env abstractions.Environment - gcpConfig *client2.GcpConfig } func (f *stateFactory) NewState(ctx context.Context, baseState composed.State) (*State, error) { @@ -65,7 +62,6 @@ func (f *stateFactory) NewState(ctx context.Context, baseState composed.State) ( KcpCluster: f.kcpCluster, SkrCluster: f.skrCluster, fileRestoreClient: fbc, - gcpConfig: f.gcpConfig, }, nil } diff --git a/pkg/skr/gcpnfsvolumerestore/state_test.go b/pkg/skr/gcpnfsvolumerestore/state_test.go index 3b88c896e..1fff0c31e 100644 --- a/pkg/skr/gcpnfsvolumerestore/state_test.go +++ b/pkg/skr/gcpnfsvolumerestore/state_test.go @@ -149,7 +149,6 @@ type testStateFactory struct { kcpCluster composed.StateCluster fileRestoreClientProvider client.ClientProvider[client2.FileRestoreClient] env abstractions.Environment - gcpConfig *client.GcpConfig fakeHttpServer *httptest.Server } @@ -201,7 +200,6 @@ func newTestStateFactoryWithObj(fakeHttpServer *httptest.Server, gcpNfsVolumeRes kcpCluster: kcpCluster, fileRestoreClientProvider: nfsRestoreClient, env: env, - gcpConfig: client.GetGcpConfig(env), fakeHttpServer: fakeHttpServer, }, nil diff --git a/pkg/testinfra/run.go b/pkg/testinfra/run.go index 1811d69ec..273329a2d 100644 --- a/pkg/testinfra/run.go +++ b/pkg/testinfra/run.go @@ -10,6 +10,7 @@ import ( awsmock "github.com/kyma-project/cloud-manager/pkg/kcp/provider/aws/mock" azuremock "github.com/kyma-project/cloud-manager/pkg/kcp/provider/azure/mock" cceemock "github.com/kyma-project/cloud-manager/pkg/kcp/provider/ccee/mock" + gcpclient "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/client" gcpmock "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/mock" "github.com/kyma-project/cloud-manager/pkg/kcp/scope" "github.com/kyma-project/cloud-manager/pkg/quota" @@ -176,11 +177,18 @@ func Start() (Infra, error) { gomega.Default.SetDefaultConsistentlyPollingInterval(200 * time.Millisecond) } + //Setup GCP env variables + _ = os.Setenv("GCP_SA_JSON_KEY_PATH", "test") + _ = os.Setenv("GCP_RETRY_WAIT_DURATION", "300ms") + _ = os.Setenv("GCP_OPERATION_WAIT_DURATION", "300ms") + _ = os.Setenv("GCP_API_TIMEOUT_DURATION", "300ms") + // init config awsconfig.InitConfig(infra.Config()) quota.InitConfig(infra.Config()) skrruntimeconfig.InitConfig(infra.Config()) scope.InitConfig(infra.Config()) + gcpclient.InitConfig(infra.Config()) infra.Config().Read() fmt.Printf("Starting with config:\n%s\n", infra.Config().PrintJson())