Skip to content

Commit

Permalink
fix lint and test
Browse files Browse the repository at this point in the history
  • Loading branch information
HomayoonAlimohammadi committed Feb 20, 2025
1 parent 69b9ee6 commit 47586fb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/k8s/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.23.4
require (
dario.cat/mergo v1.0.0
github.com/canonical/go-dqlite/v2 v2.0.0
github.com/canonical/k8s-snap-api v1.0.18-0.20250219085359-77a648b162f0
github.com/canonical/k8s-snap-api v1.0.19-0.20250220093227-e88537a97a8a
github.com/canonical/lxd v0.0.0-20250113143058-52441d41dab7
github.com/canonical/microcluster/v2 v2.1.1-0.20250127104725-631889214b18
github.com/go-logr/logr v1.4.2
Expand Down
2 changes: 2 additions & 0 deletions src/k8s/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ github.com/canonical/go-dqlite/v2 v2.0.0 h1:RNFcFVhHMh70muKKErbW35rSzqmAFswheHdA
github.com/canonical/go-dqlite/v2 v2.0.0/go.mod h1:IaIC8u4Z1UmPjuAqPzA2r83YMaMHRLoKZdHKI5uHCJI=
github.com/canonical/k8s-snap-api v1.0.18-0.20250219085359-77a648b162f0 h1:lPTugugrji2UhVILujTJA3NUi1yjRWe77HcnQLD2gH8=
github.com/canonical/k8s-snap-api v1.0.18-0.20250219085359-77a648b162f0/go.mod h1:kdXBgGo5TF93NJYHfa1bfKIzEIgE1oQriFHcVoVQUX8=
github.com/canonical/k8s-snap-api v1.0.19-0.20250220093227-e88537a97a8a h1:7slh2e8T7JXqIUhPAN1kOOznOIhTPe0CAqBw5pSivaE=
github.com/canonical/k8s-snap-api v1.0.19-0.20250220093227-e88537a97a8a/go.mod h1:kdXBgGo5TF93NJYHfa1bfKIzEIgE1oQriFHcVoVQUX8=
github.com/canonical/lxd v0.0.0-20250113143058-52441d41dab7 h1:lZCOt9/1KowNdnWXjfA1/51Uj7+R0fKtByos9EVrYn4=
github.com/canonical/lxd v0.0.0-20250113143058-52441d41dab7/go.mod h1:4Ssm3YxIz8wyazciTLDR9V0aR2GPlGIHb+S0182T5pA=
github.com/canonical/microcluster/v2 v2.1.1-0.20250127104725-631889214b18 h1:h5VJaUnE4gAKPolBTJ11HMRTEN5JyA+oR4gHkoK//6o=
Expand Down
80 changes: 52 additions & 28 deletions tests/integration/tests/test_cluster_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ def test_cluster_config(instances: List[harness.Instance]):
"pod-cidr": "10.1.0.0/16",
"service-cidr": "10.152.183.0/24",
},
"dns":{
"dns": {
"enabled": True,
"cluster-domain": "cluster.local",
"service-ip": "10.152.183.200",
"upstream-nameservers": ["/etc/resolv.conf"],
},
"ingress":{
"ingress": {
"enabled": True,
"default-tls-secret": "",
"enable-proxy-protocol": False,
},
"load-balancer":{
"load-balancer": {
"enabled": True,
"cidrs": [],
"l2-mode": True,
Expand All @@ -64,35 +64,65 @@ def test_cluster_config(instances: List[harness.Instance]):
"bgp-peer-asn": 0,
"bgp-peer-port": 0,
},
"local-storage":{
"local-storage": {
"enabled": True,
"local-path": "/var/snap/k8s/common/rawfile-storage",
"reclaim-policy": "Delete",
"default": True,
},
"gateway":{
"gateway": {
"enabled": True,
},
"metrics-server":{
"metrics-server": {
"enabled": True,
},
}
exp_cp_datastore = {"type": "k8s-dqlite"}
exp_cp_taints = ["taint1=:PreferNoSchedule", "taint2=value:PreferNoSchedule"]
exp_worker_taints = ["workerTaint1=:PreferNoSchedule", "workerTaint2=workerValue:PreferNoSchedule"]
exp_worker_taints = [
"workerTaint1=:PreferNoSchedule",
"workerTaint2=workerValue:PreferNoSchedule",
]

assert cp_resp["datastore"] == exp_cp_datastore, f"Mismatch in {cp_resp['datastore']} and {exp_cp_datastore=}"
assert cp_resp["nodeTaints"] == exp_cp_taints, f"Mismatch in {cp_resp['nodeTaints']} and {exp_cp_taints=}"
assert worker_resp["nodeTaints"] == exp_worker_taints, f"Mismatch in {worker_resp['nodeTaints']} and {exp_worker_taints=}"
assert cp_resp["status"]["network"] == exp_cp_config["network"], f"Mismatch in {cp_resp['status']['network']} and {exp_cp_config['network']=}"
assert cp_resp["status"]["dns"]["enabled"] == exp_cp_config["dns"]["enabled"], f"Mismatch in {cp_resp['status']['dns']['enabled']} and {exp_cp_config['dns']['enabled']=}"
assert cp_resp["status"]["dns"]["cluster-domain"] == exp_cp_config["dns"]["cluster-domain"], f"Mismatch in {cp_resp['status']['dns']['cluster-domain']} and {exp_cp_config['dns']['cluster-domain']=}"
assert cp_resp["status"]["dns"]["upstream-nameservers"] == exp_cp_config["dns"]["upstream-nameservers"], f"Mismatch in {cp_resp['status']['dns']['upstream-nameservers']} and {exp_cp_config['dns']['upstream-nameservers']=}"
assert cp_resp["status"]["ingress"] == exp_cp_config["ingress"], f"Mismatch in {cp_resp['status']['ingress']} and {exp_cp_config['ingress']=}"
assert cp_resp["status"]["load-balancer"] == exp_cp_config["load-balancer"], f"Mismatch in {cp_resp['status']['load-balancer']} and {exp_cp_config['load-balancer']=}"
assert cp_resp["status"]["local-storage"] == exp_cp_config["local-storage"], f"Mismatch in {cp_resp['status']['local-storage']} and {exp_cp_config['local-storage']=}"
assert cp_resp["status"]["gateway"] == exp_cp_config["gateway"], f"Mismatch in {cp_resp['status']['gateway']} and {exp_cp_config['gateway']=}"
assert cp_resp["status"]["metrics-server"] == exp_cp_config["metrics-server"], f"Mismatch in {cp_resp['status']['metrics-server']} and {exp_cp_config['metrics-server']=}"
assert (
cp_resp["datastore"] == exp_cp_datastore
), f"Mismatch in {cp_resp['datastore']} and {exp_cp_datastore=}"
assert (
cp_resp["nodeTaints"] == exp_cp_taints
), f"Mismatch in {cp_resp['nodeTaints']} and {exp_cp_taints=}"
assert (
worker_resp["nodeTaints"] == exp_worker_taints
), f"Mismatch in {worker_resp['nodeTaints']} and {exp_worker_taints=}"
assert (
cp_resp["status"]["network"] == exp_cp_config["network"]
), f"Mismatch in {cp_resp['status']['network']} and {exp_cp_config['network']=}"
assert (
cp_resp["status"]["dns"]["enabled"] == exp_cp_config["dns"]["enabled"]
), f"Mismatch in {cp_resp['status']['dns']['enabled']} and {exp_cp_config['dns']['enabled']=}"
assert (
cp_resp["status"]["dns"]["cluster-domain"]
== exp_cp_config["dns"]["cluster-domain"]
), f"Mismatch in {cp_resp['status']['dns']['cluster-domain']} and {exp_cp_config['dns']['cluster-domain']=}"
assert (
cp_resp["status"]["dns"]["upstream-nameservers"]
== exp_cp_config["dns"]["upstream-nameservers"]
), f"Mismatch in {cp_resp['status']['dns']['upstream-nameservers']} and "
"{exp_cp_config['dns']['upstream-nameservers']=}"
assert (
cp_resp["status"]["ingress"] == exp_cp_config["ingress"]
), f"Mismatch in {cp_resp['status']['ingress']} and {exp_cp_config['ingress']=}"
assert (
cp_resp["status"]["load-balancer"] == exp_cp_config["load-balancer"]
), f"Mismatch in {cp_resp['status']['load-balancer']} and {exp_cp_config['load-balancer']=}"
assert (
cp_resp["status"]["local-storage"] == exp_cp_config["local-storage"]
), f"Mismatch in {cp_resp['status']['local-storage']} and {exp_cp_config['local-storage']=}"
assert (
cp_resp["status"]["gateway"] == exp_cp_config["gateway"]
), f"Mismatch in {cp_resp['status']['gateway']} and {exp_cp_config['gateway']=}"
assert (
cp_resp["status"]["metrics-server"] == exp_cp_config["metrics-server"]
), f"Mismatch in {cp_resp['status']['metrics-server']} and {exp_cp_config['metrics-server']=}"


def get_cluster_config(instance: harness.Instance) -> Any:
Expand All @@ -110,17 +140,11 @@ def get_cluster_config(instance: harness.Instance) -> Any:
)
assert resp.returncode == 0, f"Failed to get cluster config. {resp=}"
response = json.loads(resp.stdout.decode())
assert (
response["error_code"] == 0
), f"Failed to get cluster config. {response=}"
assert (
response["error"] == ""
), f"Failed to get cluster config. {response=}"
assert response["error_code"] == 0, f"Failed to get cluster config. {response=}"
assert response["error"] == "", f"Failed to get cluster config. {response=}"

metadata = response.get("metadata")
assert (
metadata is not None
), "Metadata not found in the cluster config response."
assert metadata is not None, "Metadata not found in the cluster config response."
assert (
metadata.get("status") is not None
), "Config not found in the cluster config response."
Expand Down

0 comments on commit 47586fb

Please sign in to comment.