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

feat(cloud): implement CRUD functions for Kubernetes cloud resource #598

Conversation

anvial
Copy link
Member

@anvial anvial commented Sep 27, 2024

Description

  • Added CRUD methods in kubernetesCloudsClient to handle the creation of Kubernetes clouds.
  • Integrated the new method into the Terraform provider's CRUD functions in kubernetesCloudResource.
  • Updated the schema and model to include necessary attributes for Kubernetes cloud create/read/update/delete.

Type of change

  • Change existing resource

Environment

  • Juju controller version:

  • Terraform version:

QA steps

# get k8s cloud config yaml
microk8s.config view > test-k8s-config.yaml
terraform {
  required_providers {
    juju = {
      version = "0.15.0"
      source  = "juju/juju"
    }
  }
}

resource "juju_kubernetes_cloud" "test-k8s-cloud" {
  name = "test-k8s-cloud"
  kubernetesconfig = file("<path-to-test-k8s-config.yaml>")
}
juju clouds --controller <controller_name>
# output should demonstrate freshly added cloud to the controller

@anvial anvial requested a review from hmlanigan September 27, 2024 15:06
@anvial anvial force-pushed the JUJU-6811-implement-kubernetes-cloud-resource-create-function branch 2 times, most recently from f861c1a to a5cafb4 Compare September 30, 2024 09:53
Copy link
Member

@hmlanigan hmlanigan left a comment

Choose a reason for hiding this comment

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

The PR description does not match the code. Import, Read and Delete were also implemented.

internal/juju/kubernetes_clouds.go Outdated Show resolved Hide resolved
internal/provider/resource_kubernetes_cloud.go Outdated Show resolved Hide resolved
internal/provider/resource_kubernetes_cloud.go Outdated Show resolved Hide resolved
internal/provider/resource_kubernetes_cloud.go Outdated Show resolved Hide resolved
internal/juju/kubernetes_clouds.go Outdated Show resolved Hide resolved
internal/provider/resource_kubernetes_cloud.go Outdated Show resolved Hide resolved
Comment on lines 170 to 167
cloud, err := o.client.Clouds.ReadKubernetesCloud(
&juju.ReadKubernetesCloudInput{
Name: plan.CloudName.ValueString(),
KubernetesConfig: plan.KubernetesConfig.ValueString(),
},
)
Copy link
Member

Choose a reason for hiding this comment

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

issue: Import will not work if Read is implemented this way. You have to get the name from the ID.

internal/juju/kubernetes_clouds.go Outdated Show resolved Hide resolved
@Aflynn50 Aflynn50 self-requested a review October 1, 2024 11:43
@anvial anvial changed the title feat(kubernetes-cloud): implement create function for Kubernetes cloud resource feat(cloud): implement CRUD functions for Kubernetes cloud resource Oct 2, 2024
@anvial anvial force-pushed the JUJU-6811-implement-kubernetes-cloud-resource-create-function branch 2 times, most recently from ee55703 to 988feb7 Compare October 2, 2024 10:36
Copy link
Contributor

@Aflynn50 Aflynn50 left a comment

Choose a reason for hiding this comment

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

Left some comments, am trying some QA now!

internal/juju/kubernetes_clouds.go Outdated Show resolved Hide resolved
internal/juju/kubernetes_clouds.go Outdated Show resolved Hide resolved
internal/juju/kubernetes_clouds.go Outdated Show resolved Hide resolved
internal/juju/kubernetes_clouds.go Outdated Show resolved Hide resolved
internal/provider/resource_kubernetes_cloud.go Outdated Show resolved Hide resolved
@anvial anvial force-pushed the JUJU-6811-implement-kubernetes-cloud-resource-create-function branch from b96479c to 74e8d91 Compare October 3, 2024 13:47
internal/juju/interfaces.go Outdated Show resolved Hide resolved
internal/juju/kubernetesClouds.go Show resolved Hide resolved
internal/juju/kubernetesClouds_test.go Show resolved Hide resolved
internal/juju/kubernetesClouds_test.go Outdated Show resolved Hide resolved
internal/provider/resource_kubernetes_cloud.go Outdated Show resolved Hide resolved
internal/provider/resource_kubernetes_cloud_test.go Outdated Show resolved Hide resolved
ctlr := s.setupMocks(s.T())
defer ctlr.Finish()

s.mockKubernetesCloudClient.EXPECT().AddCloud(gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
Copy link
Member

Choose a reason for hiding this comment

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

Should check some of the input to ensure it's correct.

internal/juju/kubernetesClouds_test.go Show resolved Hide resolved
return errors.Trace(err)
}

err = kubernetesAPIClient.UpdateCloud(newCloud)
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if the created credential will need an update too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm... and what is your suggestion? to take credentials from the state and compare?

@anvial anvial force-pushed the JUJU-6811-implement-kubernetes-cloud-resource-create-function branch 3 times, most recently from 232a4c8 to 8da2f56 Compare October 7, 2024 13:22
@hmlanigan hmlanigan force-pushed the JUJU-6811-implement-kubernetes-cloud-resource-create-function branch 2 times, most recently from d63c33b to 44b5a11 Compare October 7, 2024 20:10
@anvial anvial force-pushed the JUJU-6811-implement-kubernetes-cloud-resource-create-function branch 2 times, most recently from 60cf3b8 to 351f4d3 Compare October 8, 2024 14:54
@hmlanigan hmlanigan added this to the 0.15.0 milestone Oct 8, 2024
Copy link
Member

@hmlanigan hmlanigan left a comment

Choose a reason for hiding this comment

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

Thanks for all the work @anvial!

@hmlanigan
Copy link
Member

/merge

anvial added 8 commits October 8, 2024 21:41
- Added `CreateKubernetesCloud` method in `kubernetesCloudsClient` to handle the creation of
  Kubernetes clouds.
- Integrated the new method into the Terraform provider's kubernetes resouce `Create` function in
  `kubernetesCloudResource`.
- Updated the schema and model to include necessary attributes for Kubernetes cloud creation.
… resource

- Added `Read` function in `kubernetesCloudResource` to handle reading the
  current state of the Kubernetes cloud.
- Implemented `Delete` function in `kubernetesCloudResource` to handle the
  removal of Kubernetes clouds.
- Integrated the new methods into the Terraform provider's resource lifecycle.
- Updated the schema and model to ensure proper state management during read
  and delete operations.
- Added `Update` function in `kubernetesCloudResource` to handle updating the Kubernetes cloud.
- Integrated the new method into the Terraform provider's resource lifecycle.
- Updated the schema and model to ensure proper state management during update operations.
@hmlanigan hmlanigan force-pushed the JUJU-6811-implement-kubernetes-cloud-resource-create-function branch from 7b0e404 to fd816d3 Compare October 8, 2024 21:42
@hmlanigan
Copy link
Member

I had to do one last force push to sign one of the commits, merge was failing otherwise.

@hmlanigan
Copy link
Member

/merge

@jujubot jujubot merged commit 21c1238 into juju:main Oct 9, 2024
22 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants