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

Adding K8s remote backend to BYOK #878

Merged
merged 16 commits into from
May 17, 2022
Merged

Adding K8s remote backend to BYOK #878

merged 16 commits into from
May 17, 2022

Conversation

juandiegopalomino
Copy link
Collaborator

Description

Now byo k8s cluster will store its states using k8s secrets via the official k8s backend

Safety checklist

  • This change is backwards compatible and safe to apply by existing users
  • This change will NOT lead to data loss
  • This change will NOT lead to downtime who already has an env/service setup

How has this change been tested, beside unit tests?

manually

@codecov
Copy link

codecov bot commented May 13, 2022

Codecov Report

Merging #878 (eef6134) into main (41c4c45) will decrease coverage by 0.52%.
The diff coverage is 16.48%.

@@            Coverage Diff             @@
##             main     #878      +/-   ##
==========================================
- Coverage   73.46%   72.93%   -0.53%     
==========================================
  Files         123      123              
  Lines        8190     8259      +69     
==========================================
+ Hits         6017     6024       +7     
- Misses       2173     2235      +62     
Flag Coverage Δ
unittests 72.93% <16.48%> (-0.53%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
opta/core/helm_cloud_client.py 25.51% <12.16%> (-27.13%) ⬇️
opta/core/terraform.py 61.95% <26.66%> (-0.06%) ⬇️
opta/layer.py 84.52% <100.00%> (-0.86%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 41c4c45...eef6134. Read the comment docs.

Comment on lines +9 to +11
kubernetes:
secret_suffix: "{state_storage}"
config_path: "{kubeconfig}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is this change going to affect existing usage of the helm cloud provider?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  1. No one is using it
  2. It will probably lose the current state, trying to recreate everything

modules/custom_terraform/azure-custom-terraform.md Outdated Show resolved Hide resolved
modules/custom_terraform/local-custom-terraform.md Outdated Show resolved Hide resolved
opta/core/helm_cloud_client.py Outdated Show resolved Hide resolved
opta/core/helm_cloud_client.py Outdated Show resolved Hide resolved
opta/core/helm_cloud_client.py Outdated Show resolved Hide resolved
opta/core/helm_cloud_client.py Outdated Show resolved Hide resolved
opta/core/helm_cloud_client.py Outdated Show resolved Hide resolved
opta/core/helm_cloud_client.py Outdated Show resolved Hide resolved
opta/layer.py Outdated Show resolved Hide resolved
Copy link
Contributor

@RemyDeWolf RemyDeWolf left a comment

Choose a reason for hiding this comment

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

  1. There is a 1MB limit for k8s secret, is that enough for us? (how much do we use for a typical service?

  2. Don't forget to update the documentation, the part with:
    Generate the terraform state files in tfstate - please commit these files after each apply.
    https://github.com/run-x/opta/tree/main/examples/byok-eks#deploy-a-service-to-kubernetes-with-opta__

load_opta_kube_config()
v1 = CoreV1Api()
secret_name = f"opta-config-{self.layer.state_storage()}"
if check_if_secret_exists("default", secret_name):
Copy link
Contributor

Choose a reason for hiding this comment

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

may be we should allow configuring this namespace to something lese than "default" (which would be the default value if not set)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not for now I think-- default has the benefit of always being present/available

Copy link
Contributor

Choose a reason for hiding this comment

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

ok fair enough, helm also uses to this namespace so we are consistent with that


def delete_remote_state(self) -> None:
return None
v1 = CoreV1Api()
secret_name = f"tfstate-default-{self.layer.state_storage()}"
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to have default here since it's a namespace scoped resource

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's how terraform names the secret-- we got no choice :(

@juandiegopalomino
Copy link
Collaborator Author

@RemyDeWolf
There is a 1MB limit for k8s secret, is that enough for us? (how much do we use for a typical service?
Yes, absolutely

Don't forget to update the documentation,
Done

Copy link
Collaborator

@rabbitfang rabbitfang left a comment

Choose a reason for hiding this comment

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

Minor suggestion, otherwise LGTM

except Exception:
with open(default_kube_config_filename) as f:
default_kube_config = yaml.load(f)
except YAMLError:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
except YAMLError:
except yaml.YAMLError:

(as opposed to from ruamel.yaml import YAMLError above). The yaml util library should be used instead of importing ruamel yaml directly, to discourage unsafe usage. That library reexports YAMLError.

@juandiegopalomino juandiegopalomino merged commit 63517a6 into main May 17, 2022
@juandiegopalomino juandiegopalomino deleted the jd/helm-backend branch May 17, 2022 22:52
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.

3 participants