Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
NotTheEvilOne committed Sep 15, 2021
1 parent 238bcf7 commit c135bb7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
36 changes: 18 additions & 18 deletions pkg/controller/infrastructure/ensurer/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,6 @@ import (
"github.com/hetznercloud/hcloud-go/hcloud"
)

func EnsureNetworksDeleted(ctx context.Context, client *hcloud.Client, namespace string, networks *apis.Networks) error {
if "" != networks.Workers {
name := fmt.Sprintf("%s-workers", namespace)

network, _, err := client.Network.GetByName(ctx, name)
if nil != err {
return err
} else if network != nil {
_, err := client.Network.Delete(ctx, network)
if nil != err {
return err
}
}
}

return nil
}

func EnsureNetworks(ctx context.Context, client *hcloud.Client, namespace string, networks *apis.Networks) (int, error) {
if "" != networks.Workers {
name := fmt.Sprintf("%s-workers", namespace)
Expand Down Expand Up @@ -79,3 +61,21 @@ func EnsureNetworks(ctx context.Context, client *hcloud.Client, namespace string

return -1, nil
}

func EnsureNetworksDeleted(ctx context.Context, client *hcloud.Client, namespace string, networks *apis.Networks) error {
if "" != networks.Workers {
name := fmt.Sprintf("%s-workers", namespace)

network, _, err := client.Network.GetByName(ctx, name)
if nil != err {
return err
} else if network != nil {
_, err := client.Network.Delete(ctx, network)
if nil != err {
return err
}
}
}

return nil
}
3 changes: 2 additions & 1 deletion pkg/controller/worker/machine_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"k8s.io/client-go/util/retry"
)

// findMachineImageName searches for the given machine image name and value.
func (w *workerDelegate) findMachineImageName(ctx context.Context, name, version string) (string, error) {
machineImage, err := transcoder.DecodeMachineImageNameFromCloudProfile(w.cloudProfileConfig, name, version)
if err == nil {
Expand Down Expand Up @@ -71,7 +72,7 @@ func (w *workerDelegate) findMachineImageName(ctx context.Context, name, version
return "", worker.ErrorMachineImageNotFound(name, version)
}

// GetMachineImages returns the used machine images for the `Worker` resource.
// UpdateMachineImagesStatus adds machineImages to the `WorkerStatus` resource.
func (w *workerDelegate) UpdateMachineImagesStatus(ctx context.Context) error {
if w.machineImages == nil {
if err := w.generateMachineConfig(ctx); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/worker/machines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ var _ = Describe("Machines", func() {
"mcm.gardener.cloud/role": "node",
},
"secret": map[string]interface{}{
"hcloudToken": "dummy-token",
"userData": mock.TestWorkerUserData,
"hcloudToken": []byte("dummy-token"),
"userData": []byte(mock.TestWorkerUserData),
},
},
},
Expand Down
10 changes: 5 additions & 5 deletions pkg/hcloud/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func GetCredentials(ctx context.Context, c client.Client, secretRef corev1.Secre
return ExtractCredentials(secret)
}

func extractUserPass(secret *corev1.Secret, tokenKey string) (*Token, error) {
func extractToken(secret *corev1.Secret, tokenKey string) (*Token, error) {
token, ok := secret.Data[tokenKey]
if !ok {
return nil, fmt.Errorf("missing %q field in secret", tokenKey)
Expand All @@ -83,17 +83,17 @@ func ExtractCredentials(secret *corev1.Secret) (*Credentials, error) {
return nil, fmt.Errorf("secret does not contain any data")
}

hcloud, hcloudErr := extractUserPass(secret, HcloudToken)
hcloud, hcloudErr := extractToken(secret, HcloudToken)

mcm, err := extractUserPass(secret, HcloudTokenMCM)
mcm, err := extractToken(secret, HcloudTokenMCM)
if err != nil && hcloudErr != nil {
return nil, fmt.Errorf("Need either common or machine controller manager specific Hcloud account credentials: %s, %s", hcloudErr, err)
}
ccm, err := extractUserPass(secret, HcloudTokenCCM)
ccm, err := extractToken(secret, HcloudTokenCCM)
if err != nil && hcloudErr != nil {
return nil, fmt.Errorf("Need either common or cloud controller manager specific Hcloud account credentials: %s, %s", hcloudErr, err)
}
csi, err := extractUserPass(secret, HcloudTokenCSI)
csi, err := extractToken(secret, HcloudTokenCSI)
if err != nil && hcloudErr != nil {
return nil, fmt.Errorf("Need either common or cloud controller manager specific Hcloud account credentials: %s, %s", hcloudErr, err)
}
Expand Down

0 comments on commit c135bb7

Please sign in to comment.