Skip to content

Commit

Permalink
fix: use method Cloud() instead Clouds() to read info from Juju
Browse files Browse the repository at this point in the history
  • Loading branch information
anvial committed Oct 3, 2024
1 parent bd8ea87 commit 74e8d91
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
25 changes: 10 additions & 15 deletions internal/juju/kubernetes_clouds.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/juju/juju/api/client/cloud"
k8s "github.com/juju/juju/caas/kubernetes"
k8scloud "github.com/juju/juju/caas/kubernetes/cloud"
"github.com/juju/names/v5"
"k8s.io/client-go/tools/clientcmd"
)

Expand Down Expand Up @@ -110,29 +111,23 @@ func (c *kubernetesCloudsClient) ReadKubernetesCloud(input ReadKubernetesCloudIn

client := cloud.NewClient(conn)

clouds, err := client.Clouds()
cld, err := client.Cloud(names.NewCloudTag(input.Name))
if err != nil {
return nil, errors.Annotate(err, "getting clouds")
}

for _, cloud := range clouds {
if cloud.Name == input.Name {
parentCloudName, parentCloudRegion := getParentCloudNameAndRegionFromHostCloudRegion(cloud.HostCloudRegion)
return &ReadKubernetesCloudOutput{
Name: input.Name,
ParentCloudName: parentCloudName,
ParentCloudRegion: parentCloudRegion,
}, nil
}
}

return nil, errors.NotFoundf("kubernetes cloud %q", input.Name)
parentCloudName, parentCloudRegion := getParentCloudNameAndRegion(cld.HostCloudRegion)
return &ReadKubernetesCloudOutput{
Name: input.Name,
ParentCloudName: parentCloudName,
ParentCloudRegion: parentCloudRegion,
}, nil
}

// getParentCloudNameAndRegionFromHostCloudRegion returns the parent cloud name
// getParentCloudNameAndRegion returns the parent cloud name
// and region from the host cloud region. HostCloudRegion represents the k8s
// host cloud. The format is <cloudName>/<region>.
func getParentCloudNameAndRegionFromHostCloudRegion(hostCloudRegion string) (string, string) {
func getParentCloudNameAndRegion(hostCloudRegion string) (string, string) {
parts := strings.Split(hostCloudRegion, "/")
if len(parts) != 2 {
return "", ""
Expand Down
3 changes: 0 additions & 3 deletions internal/provider/resource_kubernetes_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,5 @@ func (r *kubernetesCloudResource) trace(msg string, additionalFields ...map[stri
return
}

//SubsystemTrace(subCtx, "my-subsystem", "hello, world", map[string]interface{}{"foo": 123})
// Output:
// {"@level":"trace","@message":"hello, world","@module":"provider.my-subsystem","foo":123}
tflog.SubsystemTrace(r.subCtx, LogResourceKubernetesCloud, msg, additionalFields...)
}

0 comments on commit 74e8d91

Please sign in to comment.