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: Add Terraform module #64

Merged
merged 13 commits into from
Sep 26, 2024
Merged

Feat: Add Terraform module #64

merged 13 commits into from
Sep 26, 2024

Conversation

mvlassis
Copy link
Contributor

@mvlassis mvlassis commented Sep 18, 2024

Ref: #63

This PR creates a terraform/ directory that hosts the Terraform module for this charm. It follows the structure proposed in this spec.

To test the module:

  • Clone the repository and switch to this branch.
  • First run tox -e tflint to ensure that linting is correct
  • Change to the terraform/ directory and run terraform init.
  • Run terraform apply -var "channel=latest/edge" -var "model_name=kubeflow" --auto-approve and wait until the charm is Active and Idle.

@mvlassis
Copy link
Contributor Author

Running terraform apply produces the following error:

unit-resource-dispatcher-0: 14:57:25 ERROR unit.resource-dispatcher/0.juju-log Uncaught exception while in charm code:
Traceback (most recent call last):
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/lightkube/codecs.py", line 37, in _load_model
    module = importlib.import_module(f'lightkube.resources.{version.lower()}')
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'lightkube.resources.metacontroller_v1alpha1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./src/charm.py", line 284, in <module>
    main(ResourceDispatcherOperator)
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/ops/main.py", line 548, in main
    manager.run()
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/ops/main.py", line 527, in run
    self._emit()
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/ops/main.py", line 513, in _emit
    self.framework.reemit()
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/ops/framework.py", line 870, in reemit
    self._reemit()
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/ops/framework.py", line 950, in _reemit
    custom_handler(event)
  File "./src/charm.py", line 171, in _on_install
    self._deploy_k8s_resources()
  File "./src/charm.py", line 161, in _deploy_k8s_resources
    self.k8s_resource_handler.apply()
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/charmed_kubeflow_chisme/kubernetes/_kubernetes_resource_handler.py", line 324, in apply
    resources = self.render_manifests(force_recompute=False)
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/charmed_kubeflow_chisme/kubernetes/_kubernetes_resource_handler.py", line 272, in render_manifests
    self._manifests = codecs.load_all_yaml(
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/lightkube/codecs.py", line 105, in load_all_yaml
    return _flatten(yaml.safe_load_all(stream))
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/lightkube/codecs.py", line 98, in _flatten
    res = from_dict(obj)
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/lightkube/codecs.py", line 61, in from_dict
    model = _load_model(d['apiVersion'], d['kind'])
  File "/var/lib/juju/agents/unit-resource-dispatcher-0/charm/venv/lightkube/codecs.py", line 40, in _load_model
    raise LoadResourceError(f"{e}. If using a CRD, ensure you define a generic resource.")
lightkube.core.exceptions.LoadResourceError: No module named 'lightkube.resources.metacontroller_v1alpha1'. If using a CRD, ensure you define a generic resource.

Looking into it

@mvlassis
Copy link
Contributor Author

Following this comment, the charm needs the resource definition for metacontroller_v1alpha1. Deploying metacontroller-operator and then running terraform apply now reaches an active state:

Model     Controller  Cloud/Region      Version  SLA          Timestamp
kubeflow  uk8sx       my-k8s/localhost  3.4.5    unsupported  15:07:58+03:00

App                      Version  Status  Scale  Charm                    Channel        Rev  Address         Exposed  Message
metacontroller-operator           active      1  metacontroller-operator  latest/stable  245  10.152.183.107  no       
resource-dispatcher               active      1  resource-dispatcher      latest/edge    181  10.152.183.173  no       

Unit                        Workload  Agent  Address      Ports  Message
metacontroller-operator/0*  active    idle   10.1.90.170         
resource-dispatcher/0*      active    idle   10.1.90.172 

Copy link
Contributor

@NohaIhab NohaIhab left a comment

Choose a reason for hiding this comment

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

Thanks @mvlassis, I followed your instructions and the charm went to active. Left some comments.

In response to your comment, I think the charm going to error when metacontroller is not there is a bug, the status should be either blocked or waiting I believe. However, this is not related to your change. Can you file an issue about this?

.github/workflows/integrate.yaml Show resolved Hide resolved
terraform/outputs.tf Outdated Show resolved Hide resolved
terraform/outputs.tf Outdated Show resolved Hide resolved
terraform/README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@orfeas-k orfeas-k left a comment

Choose a reason for hiding this comment

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

One comment

.github/workflows/integrate.yaml Outdated Show resolved Hide resolved
orfeas-k
orfeas-k previously approved these changes Sep 24, 2024
Copy link
Contributor

@orfeas-k orfeas-k left a comment

Choose a reason for hiding this comment

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

Let's backport this once merged!

orfeas-k
orfeas-k previously approved these changes Sep 25, 2024
@mvlassis mvlassis merged commit 2f747a6 into main Sep 26, 2024
9 checks passed
@mvlassis mvlassis deleted the kf-6243-terraform-module branch September 26, 2024 13:47
mvlassis added a commit that referenced this pull request Sep 26, 2024
* Add Terraform module

* Update format

* Don't run terraform-checks since the charm is missing CRDs on its own

* Update terraform/README.md

Co-authored-by: Noha Ihab <49988746+NohaIhab@users.noreply.github.com>

* Update format for empty map

* Add note on why we are skipping the Terraform apply test

* Update README.md

* Update README.md

* Remove channel from terraform action

* Update default Terraform channel

* Update default Terraform channel

* Change the version of the setup operator environment

* Change setup operator action tag

---------

Co-authored-by: Noha Ihab <49988746+NohaIhab@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants