Skip to content

Commit

Permalink
fix: empty temp config (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
loic-roux-404 committed Jul 4, 2024
1 parent 47072ae commit 3f89784
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 33 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ $(TF_ROOT_DIRS_VALIDATE):
@$(eval DIR:=$(subst -validate,,$@))
terraform -chdir=$(DIR) validate -no-color $(ARGS)

.PHONY: fmt validate build build-x86 bootstrap init \
trust-ca:
@curl -k https://localhost:15000/intermediates/0 > /tmp/pebble.crt && \
sudo security add-trusted-cert -d -r trustAsRoot -k /Library/Keychains/System.keychain /tmp/pebble.crt

.PHONY: fmt validate build build-x86 bootstrap init trust-ca \
$(TF_ROOT_DIRS) $(TF_ROOT_DIRS_DESTROY) $(TF_ROOT_DIRS_INIT) \
$(TF_ROOT_DIRS_CONSOLE) $(TF_ROOT_DIRS_FMT) $(TF_ROOT_DIRS_VALIDATE)
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,11 @@ See any assets :
```bash
kubectl get all -A
```

### Tailscale

Retrieve kubeconfig :

```bash
tailscale configure kubeconfig
```
3 changes: 1 addition & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module "ingress-nginx" {

module "tailscale" {
source = "./tf-modules-k8s/tailscale"
tailscale_oauth_client = var.tailscale_oauth_client.id
tailscale_oauth_client = var.tailscale_oauth_client
}

module "internal_ca" {
Expand Down Expand Up @@ -88,7 +88,6 @@ module "paas_config" {
paas_hostname = local.paas_hostname
paas_token = module.paas.token
dex_hostname = local.dex_hostname
dex_client_id = module.dex.dex_client_id
dex_client_secret = module.dex.dex_client_secret
github_team = var.github_team
tls_skip_verify = var.cert_manager_letsencrypt_env == "local"
Expand Down
4 changes: 0 additions & 4 deletions nixos-darwin/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@
remember_owner = 0
'';
security.pki.installCACerts = true;
security.pki.certificateFiles = [
"${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
./pebble/cert.crt
];
environment.etc."pebble/config.json".text = builtins.toJSON {
pebble = {
listenAddress = "0.0.0.0:14000";
Expand Down
2 changes: 1 addition & 1 deletion nixos/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ in {
useNetworkd = true;
useDHCP = true;
firewall = {
trustedInterfaces = [ "tailscale0" ];
trustedInterfaces = [ "tailscale0" "cni0" ];
enable = true;
allowedTCPPorts = lib.mkDefault [80 443 22 6443];
allowedUDPPorts = [ config.services.tailscale.port ];
Expand Down
24 changes: 14 additions & 10 deletions nixos/tailscale-deploy.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@

let manifests = [{
file = config.sops.templates."tailscale.yaml".path;
toWait = "deployment/operator";
toWait = "deployment.apps/operator";
namespace = "tailscale";
condition = "Available";
}];
in {
services.tailscale.authKeyFile = config.sops.secrets.tailscale.path;
services.tailscale.extraUpFlags = ["--ssh" "--hostname=${config.networking.hostName}"];

system.activationScripts.tailscaleOperator.deps = [ "renderSecrets" ];
system.activationScripts.tailscaleOperator.text = "mkdir -p /var/lib/rancher/k3s/server/manifests;" +
lib.strings.concatMapStrings (manifest: ''
cp -fp ${manifest.file} /var/lib/rancher/k3s/server/manifests;
${pkgs.k3s}/bin/k3s kubectl rollout status ${manifest.toWait} -n ${manifest.file} --timeout=5m;
lib.strings.concatMapStrings (manifest: with manifest; ''
cp -fp ${file} /var/lib/rancher/k3s/server/manifests;
${pkgs.k3s}/bin/kubectl wait --for=condition=${condition} ${toWait} -n ${namespace} --timeout=2m;
'') manifests;

sops.secrets.tailscale = {};
sops.secrets.tailscale_oauth_client_id = {};
sops.secrets.tailscale_oauth_client_secret = {};

sops.templates."tailscale.yaml".content = ''
---
apiVersion: v1
kind: Namespace
metadata:
Expand All @@ -33,12 +34,15 @@ in {
name: tailscale
namespace: kube-system
spec:
chart: https://pkgs.tailscale.com/helmcharts/tailscale-operator
repo: https://pkgs.tailscale.com/helmcharts
chart: tailscale-operator
targetNamespace: tailscale
set:
oauth.clientId: ${config.sops.placeholder.tailscale_oauth_client_id}
oauth.clientSecret: ${config.sops.placeholder.tailscale_oauth_client_secret}
apiServerProxyConfig.mode: "true"
valuesContent: |
oauth:
clientId: ${config.sops.placeholder.tailscale_oauth_client_id}
clientSecret: ${config.sops.placeholder.tailscale_oauth_client_secret}
apiServerProxyConfig:
mode: "true"
waitForJobs: true
waitForHelm: true
'';
Expand Down
2 changes: 1 addition & 1 deletion nixos/temporary-configuration.nix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{...}: { networking.hostName = "k3s-paas-master-0";}
{...}: {}
6 changes: 2 additions & 4 deletions terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@ terraform {
}

provider "kubernetes" {
host = "https://${var.vm_ip}:6443"
config_path = "~/.kube/config"
exec {
api_version = "client.authentication.k8s.io/v1beta1"
args = ["zizou@localhost", "-p", "2222", "sudo", "cat", "/etc/rancher/k3s/k3s.yaml", ">", "~/.kube/config"]
command = "ssh"
args = ["configure", "kubeconfig", "tailscale-operator"]
command = "tailscale"
}
}

provider "helm" {
kubernetes {
host = "https://${var.vm_ip}:6443"
config_path = "~/.kube/config"
}
}
2 changes: 0 additions & 2 deletions tf-modules-k8s/tailscale/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ variable "tailscale_oauth_client" {
id = string
secret = string
})
nullable = true
default = null
}
1 change: 1 addition & 0 deletions tf-modules-k8s/waypoint-config/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ variable "dex_hostname" {
variable "dex_client_id" {
description = "Client ID for DEX"
type = string
default = "dex-k3s-paas"
}

variable "dex_client_secret" {
Expand Down
2 changes: 1 addition & 1 deletion tf-root-vm/tf-modules-cloud/libvirt/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ resource "libvirt_domain" "machine" {
}

provisioner "local-exec" {
command = "ssh-keygen -R localhost:22 && ssh-keygen -R 127.0.0.1:22"
command = "ssh-keygen -R localhost && ssh-keygen -R 127.0.0.1"
}
}

Expand Down
14 changes: 7 additions & 7 deletions tf-root-vm/tf-modules-cloud/tailscale/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ resource "tailscale_acl" "as_json" {
},
{
"action" : "accept",
"src" : ["autogroup:member"],
"dst" : ["tag:all"],
"src" : ["tag:all", "autogroup:member"],
"dst" : ["tag:all", "tag:k8s-operator"],
"users" : ["autogroup:nonroot"]
},
{
"action" : "accept",
"src" : ["tag:all"],
"dst" : ["tag:all"],
"action": "accept",
"src": ["autogroup:member"],
"dst": ["tag:k8s-operator"],
"users" : ["autogroup:nonroot"]
}
},
],
nodeAttrs = [
{
Expand All @@ -52,7 +52,7 @@ resource "tailscale_acl" "as_json" {
"tag:k8s" = ["tag:k8s-operator"]
}
grants = [{
src = ["autogroup:member"]
src = ["tag:all"]
dst = ["tag:k8s-operator"]
app = {
"tailscale.com/cap/kubernetes" = [{
Expand Down
12 changes: 12 additions & 0 deletions tf-root-vm/tf-modules-nix/deploy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ resource local_file "additional_nixos_vars" {
provisioner "local-exec" {
command = "git update-index --assume-unchanged ${local_file.additional_nixos_vars.filename}"
}

provisioner "local-exec" {
when = "destroy"
command = "git update-index --skip-worktree ${local_file.additional_nixos_vars.filename}"
}
}

data "external" "instantiate" {
Expand Down Expand Up @@ -154,6 +159,13 @@ resource "null_resource" "deploy" {
}
}

resource "terraform_data" "reset_tmp_config" {
depends_on = [ null_resource.deploy ]
provisioner "local-exec" {
command = "echo '{...}: {}' > ${local_file.additional_nixos_vars.filename}"
}
}

output "hostname" {
depends_on = [null_resource.deploy]
value = var.node_hostname
Expand Down

0 comments on commit 3f89784

Please sign in to comment.