Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-702 Imrpovement of cloudProviderSettings flow #705

Merged
merged 1 commit into from
Feb 13, 2024
Merged

Conversation

worryg0d
Copy link
Collaborator

@worryg0d worryg0d commented Feb 9, 2024

The PR provides devideds the whole cloudProviderSettings into different object for each cloud provider.

Closes #702

Comment on lines 849 to 928
func (c *CloudProviderOptions) FromInstAPI(instaModel *models.CloudProviderSettings) {
s := CloudProviderOpts{}
*c = append(*c, &s)

switch {
case len(instaModel.AWSSettings) > 0:
s.AWSSettings = &AWSSettings{
EncryptionKey: instaModel.AWSSettings[0].EBSEncryptionKey,
CustomVirtualNetworkID: instaModel.AWSSettings[0].CustomVirtualNetworkID,
BackupBucket: instaModel.AWSSettings[0].BackupBucket,
}
case len(instaModel.GCPSettings) > 0:
s.GCPSettings = &GCPSettings{
CustomVirtualNetworkID: instaModel.GCPSettings[0].CustomVirtualNetworkID,
DisableSnapshotAutoExpiry: instaModel.GCPSettings[0].DisableSnapshotAutoExpiry,
}
case len(instaModel.AzureSettings) > 0:
s.AzureSettings = &AzureSettings{
ResourceGroup: instaModel.AzureSettings[0].ResourceGroup,
CustomVirtualNetworkID: instaModel.AzureSettings[0].CustomVirtualNetworkID,
StorageNetwork: instaModel.AzureSettings[0].StorageNetwork,
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we will append only if s is not nil:

func (c *CloudProviderOptions) FromInstAPI(instaModel *models.CloudProviderSettings) {
	var s *CloudProviderOpts

	switch {
	case len(instaModel.AWSSettings) > 0:
		s = &CloudProviderOpts{
			AWSSettings: &AWSSettings{
				EncryptionKey:          instaModel.AWSSettings[0].EBSEncryptionKey,
				CustomVirtualNetworkID: instaModel.AWSSettings[0].CustomVirtualNetworkID,
				BackupBucket:           instaModel.AWSSettings[0].BackupBucket,
			},
		}
	case len(instaModel.GCPSettings) > 0:
		s = &CloudProviderOpts{
			GCPSettings: &GCPSettings{
				CustomVirtualNetworkID:    instaModel.GCPSettings[0].CustomVirtualNetworkID,
				DisableSnapshotAutoExpiry: instaModel.GCPSettings[0].DisableSnapshotAutoExpiry,
			},
		}
	case len(instaModel.AzureSettings) > 0:
		s = &CloudProviderOpts{
			AzureSettings: &AzureSettings{
				ResourceGroup:          instaModel.AzureSettings[0].ResourceGroup,
				CustomVirtualNetworkID: instaModel.AzureSettings[0].CustomVirtualNetworkID,
				StorageNetwork:         instaModel.AzureSettings[0].StorageNetwork,
			},
		}

		if s != nil {
			*c = append(*c, s)
		}
	}
}

wdyt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense. Done.

@worryg0d worryg0d added enhancement New feature or request refactor Code improvements or refactorings labels Feb 12, 2024
@worryg0d worryg0d force-pushed the issue-702 branch 6 times, most recently from 6be9ce3 to 026a348 Compare February 12, 2024 11:44
Region string `json:"region"`
// A logical name for the data centre within a cluster.
// These names must be unique in the cluster.
Name string `json:"name,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Makefile Outdated
kubectl apply -f ~/creds_secret.yaml
$(KUSTOMIZE) build config/default | kubectl apply -f -
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls comment kustomization

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 119 to 120
Network string `json:"network"`
Tags map[string]string `json:"tags,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

switch {
case len(instaModel.AWSSettings) > 0:
setting := instaModel.AWSSettings[0]
s.AWSSettings = append(s.AWSSettings, &AWSSettings{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use append

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return nil
}

func (s *GenericDataCentreSpec) cloudProviderSettingsPresented() bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasCloudProviderSettings()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 447 to 459
fieldSet := 0

if s.AWSSettings != nil {
fieldSet++
}
if s.AzureSettings != nil {
fieldSet++
}
if s.GCPSettings != nil {
fieldSet++
}

if fieldSet > 1 {
return errors.New("only one of [awsSettings, gcpSettings, azureSettings] should be set")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if sum := len(s.AWSSettings) + len(s.AzureSettings) + len(s.GCPSettings); sum > 1 { return err } 

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@testisnullus testisnullus merged commit 10a2b46 into main Feb 13, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactor Code improvements or refactorings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Categorize CloudProviderSettings
3 participants