diff --git a/.gitignore b/.gitignore index 4cb7d403..1fbf642e 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,6 @@ test/__debug_bin automation/sandbox automation/tests/**/*.log *.env +kubectl +.gitignore +ndb-operator.code-workspace diff --git a/NDB_Secret_Securing_With_RBAC.pdf b/NDB_Secret_Securing_With_RBAC.pdf new file mode 100644 index 00000000..5e07ed27 Binary files /dev/null and b/NDB_Secret_Securing_With_RBAC.pdf differ diff --git a/api/v1alpha1/database_types.go b/api/v1alpha1/database_types.go index 06247563..e1ec7f4c 100644 --- a/api/v1alpha1/database_types.go +++ b/api/v1alpha1/database_types.go @@ -86,8 +86,11 @@ type Instance struct { // Description of the database instance Description string `json:"description"` // Id of the cluster to provision the database on + // +optional ClusterId string `json:"clusterId"` // +optional + ClusterName string `json:"clusterName"` + // +optional Profiles *Profiles `json:"profiles"` // Name of the secret holding the credentials for the database instance (password and ssh key) CredentialSecret string `json:"credentialSecret"` @@ -118,8 +121,11 @@ type Clone struct { // Type of parent clone Type string `json:"type"` // Id of the cluster to clone the database on + // +optional ClusterId string `json:"clusterId"` // +optional + ClusterName string `json:"clusterName"` + // +optional Profiles *Profiles `json:"profiles"` // Name of the secret holding the credentials for the database instance (password and ssh key) CredentialSecret string `json:"credentialSecret"` diff --git a/api/v1alpha1/webhook_helpers.go b/api/v1alpha1/webhook_helpers.go index 45559d8f..60b2d720 100644 --- a/api/v1alpha1/webhook_helpers.go +++ b/api/v1alpha1/webhook_helpers.go @@ -59,8 +59,14 @@ func (v *CloningWebhookHandler) validateCreate(spec *DatabaseSpec, errors *field *errors = append(*errors, field.Invalid(clonePath.Child("name"), clone.Name, "A valid Clone Name must be specified")) } - if err := util.ValidateUUID(clone.ClusterId); err != nil { - *errors = append(*errors, field.Invalid(clonePath.Child("clusterId"), clone.ClusterId, "ClusterId field must be a valid UUID")) + if clone.ClusterId == "" && clone.ClusterName == "" { + *errors = append(*errors, field.Invalid(clonePath.Child("clusterName"), clone.ClusterId, "ClusterId and ClusterName field cannot be blank")) + } + + if clone.ClusterId != "" { + if err := util.ValidateUUID(clone.ClusterId); err != nil { + *errors = append(*errors, field.Invalid(clonePath.Child("clusterId"), clone.ClusterId, "ClusterId field must be a valid UUID")) + } } if clone.CredentialSecret == "" { @@ -174,8 +180,14 @@ func (v *ProvisioningWebhookHandler) validateCreate(spec *DatabaseSpec, errors * *errors = append(*errors, field.Invalid(instancePath.Child("name"), instance.Name, "A valid Database Instance Name must be specified")) } - if err := util.ValidateUUID(instance.ClusterId); err != nil { - *errors = append(*errors, field.Invalid(instancePath.Child("clusterId"), instance.ClusterId, "ClusterId field must be a valid UUID")) + if instance.ClusterId == "" && instance.ClusterName == "" { + *errors = append(*errors, field.Invalid(instancePath.Child("clusterName"), instance.ClusterId, "ClusterId and ClusterName field cannot be blank")) + } + + if instance.ClusterId != "" { + if err := util.ValidateUUID(instance.ClusterId); err != nil { + *errors = append(*errors, field.Invalid(instancePath.Child("clusterId"), instance.ClusterId, "ClusterId field must be a valid UUID")) + } } if instance.Size < 10 { diff --git a/api/v1alpha1/webhook_suite_test.go b/api/v1alpha1/webhook_suite_test.go index 2173c2db..0960225b 100644 --- a/api/v1alpha1/webhook_suite_test.go +++ b/api/v1alpha1/webhook_suite_test.go @@ -172,8 +172,19 @@ var _ = Describe("Webhook Tests", func() { Expect(errMsg).To(ContainSubstring("ClusterId field must be a valid UUID")) }) - It("Should check for missing CredentialSecret", func() { + It("Should check for missing ClusterId and ClusterName", func() { database := createDefaultDatabase("db3") + database.Spec.Instance.ClusterId = "" + database.Spec.Instance.ClusterName = "" + + err := k8sClient.Create(context.Background(), database) + Expect(err).To(HaveOccurred()) + errMsg := err.(*errors.StatusError).ErrStatus.Message + Expect(errMsg).To(ContainSubstring("ClusterId and ClusterName field cannot be blank")) + }) + + It("Should check for missing CredentialSecret", func() { + database := createDefaultDatabase("db4") database.Spec.Instance.CredentialSecret = "" err := k8sClient.Create(context.Background(), database) @@ -183,7 +194,7 @@ var _ = Describe("Webhook Tests", func() { }) It("Should check for size < 10'", func() { - database := createDefaultDatabase("db4") + database := createDefaultDatabase("db5") database.Spec.Instance.Size = 1 err := k8sClient.Create(context.Background(), database) @@ -193,7 +204,7 @@ var _ = Describe("Webhook Tests", func() { }) It("Should check for missing Type", func() { - database := createDefaultDatabase("db5") + database := createDefaultDatabase("db6") database.Spec.Instance.Type = "" err := k8sClient.Create(context.Background(), database) @@ -203,7 +214,7 @@ var _ = Describe("Webhook Tests", func() { }) It("Should check for invalid Type'", func() { - database := createDefaultDatabase("db6") + database := createDefaultDatabase("db7") database.Spec.Instance.Type = "invalid" err := k8sClient.Create(context.Background(), database) @@ -214,13 +225,13 @@ var _ = Describe("Webhook Tests", func() { When("Profiles missing", func() { It("Should not error out for missing Profiles: Open-source engines", func() { - database := createDefaultDatabase("db7") + database := createDefaultDatabase("db8") err := k8sClient.Create(context.Background(), database) Expect(err).ToNot(HaveOccurred()) }) It("Should error out for missing Profiles: Closed-source engines", func() { - database := createDefaultDatabase("db8") + database := createDefaultDatabase("db9") database.Spec.Instance.Type = common.DATABASE_TYPE_MSSQL err := k8sClient.Create(context.Background(), database) @@ -232,7 +243,7 @@ var _ = Describe("Webhook Tests", func() { When("AdditionalArguments for MYSQL specified", func() { It("Should not error for valid MYSQL additionalArguments", func() { - database := createDefaultDatabase("db9") + database := createDefaultDatabase("db10") database.Spec.Instance.Type = common.DATABASE_TYPE_MYSQL database.Spec.Instance.AdditionalArguments = map[string]string{ "listener_port": "3306", @@ -242,7 +253,7 @@ var _ = Describe("Webhook Tests", func() { Expect(err).ToNot(HaveOccurred()) }) It("Should error out for invalid MYSQL additionalArguments", func() { - database := createDefaultDatabase("db10") + database := createDefaultDatabase("db11") database.Spec.Instance.Type = common.DATABASE_TYPE_MYSQL database.Spec.Instance.AdditionalArguments = map[string]string{ "invalid": "invalid", @@ -257,7 +268,7 @@ var _ = Describe("Webhook Tests", func() { When("AdditionalArguments for PostGres specified", func() { It("Should not error for valid Postgres additionalArguments", func() { - database := createDefaultDatabase("db11") + database := createDefaultDatabase("db12") database.Spec.Instance.AdditionalArguments = map[string]string{ "listener_port": "5432", } @@ -267,7 +278,7 @@ var _ = Describe("Webhook Tests", func() { }) It("Should error out for invalid Postgres additionalArguments", func() { - database := createDefaultDatabase("db12") + database := createDefaultDatabase("db13") database.Spec.Instance.AdditionalArguments = map[string]string{ "listener_port": "5432", "invalid": "invalid", @@ -282,7 +293,7 @@ var _ = Describe("Webhook Tests", func() { When("AdditionalArguments for MongoDB specified", func() { It("Should not error for valid MongoDB additionalArguments", func() { - database := createDefaultDatabase("db13") + database := createDefaultDatabase("db14") database.Spec.Instance.Type = common.DATABASE_TYPE_MONGODB database.Spec.Instance.AdditionalArguments = map[string]string{ "listener_port": "5432", @@ -295,7 +306,7 @@ var _ = Describe("Webhook Tests", func() { }) It("Should error out for invalid MongoDB additionalArguments", func() { - database := createDefaultDatabase("db14") + database := createDefaultDatabase("db15") database.Spec.Instance.Type = common.DATABASE_TYPE_MONGODB database.Spec.Instance.AdditionalArguments = map[string]string{ "listener_port": "5432", @@ -312,7 +323,7 @@ var _ = Describe("Webhook Tests", func() { When("AdditionalArguments for MSSQL specified", func() { It("Should not error for valid MSSQL additionalArguments", func() { - database := createDefaultDatabase("db15") + database := createDefaultDatabase("db16") database.Spec.Instance.Type = common.DATABASE_TYPE_MSSQL database.Spec.Instance.Profiles = &Profiles{ Software: Profile{ @@ -335,7 +346,7 @@ var _ = Describe("Webhook Tests", func() { Expect(err).ToNot(HaveOccurred()) }) It("Should error out for invalid MSSQL additionalArguments", func() { - database := createDefaultDatabase("db16") + database := createDefaultDatabase("db17") database.Spec.Instance.Type = common.DATABASE_TYPE_MSSQL database.Spec.Instance.AdditionalArguments = map[string]string{ "invalid": "invalid", @@ -376,8 +387,19 @@ var _ = Describe("Webhook Tests", func() { Expect(errMsg).To(ContainSubstring("ClusterId field must be a valid UUID")) }) + It("Should check for missing ClusterId and ClusterName", func() { + database := createDefaultDatabase("clone3") + database.Spec.Instance.ClusterId = "" + database.Spec.Instance.ClusterName = "" + + err := k8sClient.Create(context.Background(), database) + Expect(err).To(HaveOccurred()) + errMsg := err.(*errors.StatusError).ErrStatus.Message + Expect(errMsg).To(ContainSubstring("ClusterId and ClusterName field cannot be blank")) + }) + It("Should check for missing CredentialSecret", func() { - clone := createDefaultClone("clone3") + clone := createDefaultClone("clone4") clone.Spec.Clone.CredentialSecret = "" err := k8sClient.Create(context.Background(), clone) @@ -387,7 +409,7 @@ var _ = Describe("Webhook Tests", func() { }) It("Should check for missing TimeZone", func() { - clone := createDefaultClone("clone4") + clone := createDefaultClone("clone5") clone.Spec.Clone.TimeZone = "" err := k8sClient.Create(context.Background(), clone) @@ -397,7 +419,7 @@ var _ = Describe("Webhook Tests", func() { }) It("Should check for missing/invalid Type", func() { - clone := createDefaultClone("clone5") + clone := createDefaultClone("clone6") clone.Spec.Clone.Type = "" err := k8sClient.Create(context.Background(), clone) @@ -407,7 +429,7 @@ var _ = Describe("Webhook Tests", func() { }) It("Should check for sourceDatabaseId", func() { - clone := createDefaultClone("clone6") + clone := createDefaultClone("clone7") clone.Spec.Clone.SourceDatabaseId = "" err := k8sClient.Create(context.Background(), clone) @@ -417,7 +439,7 @@ var _ = Describe("Webhook Tests", func() { }) It("Should check for snapshotId", func() { - clone := createDefaultClone("clone7") + clone := createDefaultClone("clone8") clone.Spec.Clone.SnapshotId = "" err := k8sClient.Create(context.Background(), clone) @@ -427,7 +449,7 @@ var _ = Describe("Webhook Tests", func() { }) It("Should check for invalid Type'", func() { - clone := createDefaultClone("clone8") + clone := createDefaultClone("clone9") clone.Spec.Clone.Type = "invalid" err := k8sClient.Create(context.Background(), clone) @@ -438,13 +460,13 @@ var _ = Describe("Webhook Tests", func() { When("Profiles missing", func() { It("Should not error out for missing Profiles: Open-source engines", func() { - clone := createDefaultClone("clone9") + clone := createDefaultClone("clone10") err := k8sClient.Create(context.Background(), clone) Expect(err).ToNot(HaveOccurred()) }) It("Should error out for missing Profiles: Closed-source engines", func() { - clone := createDefaultClone("clone10") + clone := createDefaultClone("clone11") clone.Spec.Clone.Type = common.DATABASE_TYPE_MSSQL err := k8sClient.Create(context.Background(), clone) @@ -456,7 +478,7 @@ var _ = Describe("Webhook Tests", func() { When("AdditionalArguments for MYSQL specified", func() { It("Should not error for valid MYSQL additionalArguments", func() { - clone := createDefaultClone("clone11") + clone := createDefaultClone("clone12") clone.Spec.Clone.Type = common.DATABASE_TYPE_MYSQL clone.Spec.Clone.AdditionalArguments = map[string]string{ "expireInDays": "30", @@ -471,7 +493,7 @@ var _ = Describe("Webhook Tests", func() { Expect(err).ToNot(HaveOccurred()) }) It("Should error out for invalid MYSQL additionalArguments", func() { - clone := createDefaultClone("clone12") + clone := createDefaultClone("clone13") clone.Spec.Clone.Type = common.DATABASE_TYPE_MYSQL clone.Spec.Clone.AdditionalArguments = map[string]string{ "invalid": "invalid", @@ -486,7 +508,7 @@ var _ = Describe("Webhook Tests", func() { When("AdditionalArguments for PostGres specified", func() { It("Should not error for valid Postgres additionalArguments", func() { - clone := createDefaultClone("clone13") + clone := createDefaultClone("clone14") clone.Spec.Clone.AdditionalArguments = map[string]string{ "expireInDays": "30", "expiryDateTimezone": common.TIMEZONE_UTC, @@ -501,7 +523,7 @@ var _ = Describe("Webhook Tests", func() { }) It("Should error out for invalid Postgres additionalArguments", func() { - clone := createDefaultClone("clone14") + clone := createDefaultClone("clone15") clone.Spec.Clone.AdditionalArguments = map[string]string{ "invalid": "invalid", } @@ -515,7 +537,7 @@ var _ = Describe("Webhook Tests", func() { When("AdditionalArguments for MongoDB specified", func() { It("Should not error for valid MongoDB additionalArguments", func() { - clone := createDefaultClone("clone15") + clone := createDefaultClone("clone16") clone.Spec.Clone.Type = common.DATABASE_TYPE_MONGODB clone.Spec.Clone.AdditionalArguments = map[string]string{ "expireInDays": "30", @@ -531,7 +553,7 @@ var _ = Describe("Webhook Tests", func() { }) It("Should error out for invalid MongoDB additionalArguments", func() { - clone := createDefaultClone("clone16") + clone := createDefaultClone("clone17") clone.Spec.Clone.Type = common.DATABASE_TYPE_MONGODB clone.Spec.Clone.AdditionalArguments = map[string]string{ "invalid": "invalid", @@ -546,7 +568,7 @@ var _ = Describe("Webhook Tests", func() { When("AdditionalArguments for MSSQL specified", func() { It("Should not error for valid MSSQL additionalArguments", func() { - clone := createDefaultClone("clone17") + clone := createDefaultClone("clone18") clone.Spec.Clone.Type = common.DATABASE_TYPE_MSSQL clone.Spec.Clone.Profiles = &Profiles{ Software: Profile{ @@ -578,7 +600,7 @@ var _ = Describe("Webhook Tests", func() { Expect(err).ToNot(HaveOccurred()) }) It("Should error out for invalid MSSQL additionalArguments", func() { - clone := createDefaultClone("clone18") + clone := createDefaultClone("clone19") clone.Spec.Clone.Type = common.DATABASE_TYPE_MSSQL clone.Spec.Clone.AdditionalArguments = map[string]string{ "invalid": "invalid", diff --git a/config/crd/bases/ndb.nutanix.com_databases.yaml b/config/crd/bases/ndb.nutanix.com_databases.yaml index c9c2438d..83b50158 100644 --- a/config/crd/bases/ndb.nutanix.com_databases.yaml +++ b/config/crd/bases/ndb.nutanix.com_databases.yaml @@ -58,6 +58,8 @@ spec: clusterId: description: Id of the cluster to clone the database on type: string + clusterName: + type: string credentialSecret: description: Name of the secret holding the credentials for the database instance (password and ssh key) @@ -119,7 +121,6 @@ spec: description: Type of parent clone type: string required: - - clusterId - credentialSecret - name - snapshotId @@ -137,6 +138,8 @@ spec: clusterId: description: Id of the cluster to provision the database on type: string + clusterName: + type: string credentialSecret: description: Name of the secret holding the credentials for the database instance (password and ssh key) @@ -233,7 +236,6 @@ spec: type: type: string required: - - clusterId - credentialSecret - name - size diff --git a/controller_adapters/database.go b/controller_adapters/database.go index c2bc4506..630ed4c9 100644 --- a/controller_adapters/database.go +++ b/controller_adapters/database.go @@ -70,9 +70,16 @@ func (d *Database) GetDescription() string { func (d *Database) GetClusterId() string { if d.IsClone() { - return d.Spec.Clone.ClusterId + return d.Spec.Clone.ClusterId } - return d.Spec.Instance.ClusterId + return d.Spec.Instance.ClusterId +} + +func (d *Database) GetClusterName() string { + if d.IsClone() { + return d.Spec.Clone.ClusterName + } + return d.Spec.Instance.ClusterName } func (d *Database) GetProfileResolvers() ndb_api.ProfileResolvers { diff --git a/error.log b/error.log new file mode 100644 index 00000000..5f643595 --- /dev/null +++ b/error.log @@ -0,0 +1,22 @@ +test -s /Users/swastikghosh/Documents/NCSU/ECE517/Program4/ndb-operator/bin/controller-gen || GOBIN=/Users/swastikghosh/Documents/NCSU/ECE517/Program4/ndb-operator/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.9.2 +/Users/swastikghosh/Documents/NCSU/ECE517/Program4/ndb-operator/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases +/Users/swastikghosh/Documents/NCSU/ECE517/Program4/ndb-operator/bin/kustomize build config/crd | kubectl delete --ignore-not-found=false -f - +customresourcedefinition.apiextensions.k8s.io "databases.ndb.nutanix.com" deleted +customresourcedefinition.apiextensions.k8s.io "ndbservers.ndb.nutanix.com" deleted +/Users/swastikghosh/Documents/NCSU/ECE517/Program4/ndb-operator/bin/kustomize build config/crd | kubectl apply -f - +customresourcedefinition.apiextensions.k8s.io/databases.ndb.nutanix.com created +customresourcedefinition.apiextensions.k8s.io/ndbservers.ndb.nutanix.com created +/Users/swastikghosh/Documents/NCSU/ECE517/Program4/ndb-operator/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..." +go fmt ./... +go vet ./... +ENABLE_WEBHOOKS=false go run ./main.go + +Username : ntnx3 +Password : ntnx3 +caCert : + + +Username : ntnx3 +Password : ntnx3 +caCert : + diff --git a/ndb_api/clone_helpers.go b/ndb_api/clone_helpers.go index aa0f787e..7b26f02c 100644 --- a/ndb_api/clone_helpers.go +++ b/ndb_api/clone_helpers.go @@ -15,7 +15,9 @@ package ndb_api import ( "context" + "encoding/json" "fmt" + "net/http" "github.com/nutanix-cloud-native/ndb-operator/common" "github.com/nutanix-cloud-native/ndb-operator/ndb_client" @@ -40,6 +42,11 @@ func GenerateDeprovisionCloneRequest() (req *CloneDeprovisionRequest) { // This function generates and returns a request for cloning a database on NDB func GenerateCloningRequest(ctx context.Context, ndb_client *ndb_client.NDBClient, database DatabaseInterface, reqData map[string]interface{}) (requestBody *DatabaseCloneRequest, err error) { + var localClusterId string + var localURL string + var httpResponse *http.Response + var result map[string]interface{} + log := ctrllog.FromContext(ctx) log.Info("Entered ndb_api.GenerateCloningRequest", "database name", database.GetName()) @@ -55,13 +62,42 @@ func GenerateCloningRequest(ctx context.Context, ndb_client *ndb_client.NDBClien // Required for dbParameterProfileIdInstance in MSSQL action args reqData[common.PROFILE_MAP_PARAM] = profilesMap + if database.GetClusterId() != "" { + localClusterId = database.GetClusterId() + } else { + localURL = "clusters/name/" + database.GetClusterName() + httpResponse, err = ndb_client.Get(localURL) + if err != nil { + fmt.Println("Error sending request:", err) + return + } + if httpResponse.StatusCode != http.StatusOK { + fmt.Println("Error: Unexpected status code", httpResponse.Status) + return + } + + err = json.NewDecoder(httpResponse.Body).Decode(&result) + if err != nil { + fmt.Println("Error decoding JSON:", err) + return + } + + id, ok := result["id"].(string) + if !ok { + fmt.Println("Error: 'id' field not found or not a string") + return + } + localClusterId = id + fmt.Println("Cluster ID Obtained : " + localClusterId) + } + // Creating a provisioning request based on the database type requestBody = &DatabaseCloneRequest{ Name: database.GetName(), Description: database.GetDescription(), CreateDbServer: true, Clustered: false, - NxClusterId: database.GetClusterId(), + NxClusterId: localClusterId, //database.GetClusterId(), // SSHPublicKey populated by request appenders for non mssql dbs DbServerId: "", DbServerClusterId: "", @@ -78,7 +114,7 @@ func GenerateCloningRequest(ctx context.Context, ndb_client *ndb_client.NDBClien ComputeProfileId: profilesMap[common.PROFILE_TYPE_COMPUTE].Id, NetworkProfileId: profilesMap[common.PROFILE_TYPE_NETWORK].Id, NewDbServerTimeZone: "", - NxClusterId: database.GetClusterId(), + NxClusterId: localClusterId, //database.GetClusterId(), Properties: make([]string, 0), }, }, diff --git a/ndb_api/db_helpers.go b/ndb_api/db_helpers.go index 0af5412a..efa14f3f 100644 --- a/ndb_api/db_helpers.go +++ b/ndb_api/db_helpers.go @@ -18,8 +18,10 @@ package ndb_api import ( "context" + "encoding/json" "errors" "fmt" + "net/http" "strconv" "github.com/nutanix-cloud-native/ndb-operator/common" @@ -31,6 +33,11 @@ import ( // This function generates and returns a request for provisioning a database (and a dbserver vm) on NDB // The database provisioned has a NONE time machine SLA attached to it, and uses the default OOB profiles func GenerateProvisioningRequest(ctx context.Context, ndb_client *ndb_client.NDBClient, database DatabaseInterface, reqData map[string]interface{}) (requestBody *DatabaseProvisionRequest, err error) { + var localClusterId string + var localURL string + var httpResponse *http.Response + var result map[string]interface{} + log := ctrllog.FromContext(ctx) log.Info("Entered ndb_api.GenerateProvisioningRequest", "database name", database.GetName(), "database type", database.GetInstanceType()) @@ -65,6 +72,35 @@ func GenerateProvisioningRequest(ctx context.Context, ndb_client *ndb_client.NDB return } + if database.GetClusterId() != "" { + localClusterId = database.GetClusterId() + } else { + localURL = "clusters/name/" + database.GetClusterName() + httpResponse, err = ndb_client.Get(localURL) + if err != nil { + fmt.Println("Error sending request:", err) + return + } + if httpResponse.StatusCode != http.StatusOK { + fmt.Println("Error: Unexpected status code", httpResponse.Status) + return + } + + err = json.NewDecoder(httpResponse.Body).Decode(&result) + if err != nil { + fmt.Println("Error decoding JSON:", err) + return + } + + id, ok := result["id"].(string) + if !ok { + fmt.Println("Error: 'id' field not found or not a string") + return + } + localClusterId = id + fmt.Println("Cluster ID Obtained : " + localClusterId) + } + // Creating a provisioning request based on the database type requestBody = &DatabaseProvisionRequest{ DatabaseType: GetDatabaseEngineName(database.GetInstanceType()), @@ -78,7 +114,7 @@ func GenerateProvisioningRequest(ctx context.Context, ndb_client *ndb_client.NDB NewDbServerTimeZone: database.GetTimeZone(), CreateDbServer: true, NodeCount: 1, - NxClusterId: database.GetClusterId(), + NxClusterId: localClusterId, //database.GetClusterId(), Clustered: false, AutoTuneStagingDrive: true, diff --git a/ndb_api/db_helpers_test.go b/ndb_api/db_helpers_test.go index f39af280..ccb5e955 100644 --- a/ndb_api/db_helpers_test.go +++ b/ndb_api/db_helpers_test.go @@ -19,6 +19,7 @@ const ( TEST_INSTANCE_TYPE = "testInstance" TEST_TIMEZONE = "test-timezone" TEST_CLUSTER_ID = "test-cluster-id" + TEST_CLUSTER_NAME = "test-cluster-name" TEST_INSTANCE_SIZE = 100 ) @@ -1285,6 +1286,7 @@ func TestGenerateProvisioningRequest_AgainstDifferentReqData(t *testing.T) { mockDatabase.On("GetProfileResolvers").Return(profileResolvers) mockDatabase.On("GetTimeZone").Return(TEST_TIMEZONE) mockDatabase.On("GetClusterId").Return(TEST_CLUSTER_ID) + mockDatabase.On("GetClusterName").Return(TEST_CLUSTER_NAME) mockDatabase.On("GetInstanceSize").Return(TEST_INSTANCE_SIZE) mockDatabase.On("GetInstanceDatabaseNames").Return(TEST_DB_NAMES) mockDatabase.On("GetAdditionalArguments").Return(map[string]string{}) diff --git a/ndb_api/interface_mock_test.go b/ndb_api/interface_mock_test.go index 4190debc..4510cfdd 100644 --- a/ndb_api/interface_mock_test.go +++ b/ndb_api/interface_mock_test.go @@ -40,6 +40,12 @@ func (m *MockDatabaseInterface) GetClusterId() string { return args.String(0) } +// GetClusterName is a mock implementation of the GetClusterName method in the Database interface +func (m *MockDatabaseInterface) GetClusterName() string { + args := m.Called() + return args.String(0) +} + // GetProfileResolvers is a mock implementation of the GetProfileResolvers method in the Database interface func (m *MockDatabaseInterface) GetProfileResolvers() ProfileResolvers { args := m.Called() diff --git a/ndb_api/interfaces.go b/ndb_api/interfaces.go index f0c3dedd..1d63f3ab 100644 --- a/ndb_api/interfaces.go +++ b/ndb_api/interfaces.go @@ -38,6 +38,7 @@ type DatabaseInterface interface { GetName() string GetDescription() string GetClusterId() string + GetClusterName() string GetProfileResolvers() ProfileResolvers GetCredentialSecret() string GetTimeZone() string diff --git a/ndb_client/ndb_client.go b/ndb_client/ndb_client.go index 379384a0..61ed06e3 100644 --- a/ndb_client/ndb_client.go +++ b/ndb_client/ndb_client.go @@ -47,7 +47,7 @@ func NewNDBClient(username, password, url, caCert string, skipVerify bool) *NDBC func (ndbClient *NDBClient) Get(path string) (*http.Response, error) { url := ndbClient.url + "/" + path req, err := http.NewRequest(http.MethodGet, url, nil) - if err != nil { + if err != nil { // fmt.Println(err) return nil, err } @@ -59,7 +59,7 @@ func (ndbClient *NDBClient) Post(path string, body interface{}) (*http.Response, url := ndbClient.url + "/" + path payload, _ := json.Marshal(body) req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(payload)) - if err != nil { + if err != nil { // fmt.Println(err) return nil, err } @@ -72,7 +72,7 @@ func (ndbClient *NDBClient) Delete(path string, body interface{}) (*http.Respons url := ndbClient.url + "/" + path payload, _ := json.Marshal(body) req, err := http.NewRequest(http.MethodDelete, url, bytes.NewBuffer(payload)) - if err != nil { + if err != nil { // fmt.Println(err) return nil, err }