Skip to content

Commit

Permalink
Support kube-control v2 schema
Browse files Browse the repository at this point in the history
  • Loading branch information
addyess committed Nov 13, 2024
1 parent 084b17c commit a48f7ce
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ on:
jobs:
call-inclusive-naming-check:
name: Inclusive Naming
uses: canonical-web-and-design/Inclusive-naming/.github/workflows/woke.yaml@main
uses: canonical/inclusive-naming/.github/workflows/woke.yaml@main
with:
fail-on-error: "true"

lint-unit:
name: Lint Unit
uses: charmed-kubernetes/workflows/.github/workflows/lint-unit.yaml@main
with:
python: "['3.8', '3.9', '3.10', '3.11']"
python: "['3.8', '3.10', '3.12']"
needs:
- call-inclusive-naming-check

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
backports.cached-property
ops>=1.3.0,<2.0.0
ops
lightkube>=0.10.1,<1.0.0
pyyaml
pydantic==1.*
ops.manifest>=1.1.0,<2.0.0
git+https://github.com/charmed-kubernetes/interface-kube-control.git@6dd289d1c795fdeda1bed17873b8d6562227c829#subdirectory=ops
git+https://github.com/charmed-kubernetes/interface-kube-control.git@KU-1998/use-secrets#subdirectory=ops
git+https://github.com/charmed-kubernetes/interface-tls-certificates.git@339efe3823b9728d16cdf5bcd1fc3b5de4e68923#subdirectory=ops
10 changes: 7 additions & 3 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, *args):
super().__init__(*args)

# Relation Validator and datastore
self.kube_control = KubeControlRequirer(self)
self.kube_control = KubeControlRequirer(self, schemas="0,1")
self.certificates = CertificatesRequires(self)
# Config Validator and datastore
self.charm_config = CharmConfig(self)
Expand Down Expand Up @@ -113,7 +113,7 @@ def _update_status(self, _):
self.app.status = ActiveStatus(self.collector.long_version)

def _kube_control(self, event):
self.kube_control.set_auth_request(self.unit.name)
self.kube_control.set_auth_request(self.unit.name, "system:masters")
return self._merge_config(event)

def _check_kube_control(self, event):
Expand All @@ -137,6 +137,10 @@ def _check_kube_control(self, event):
return True

def _check_certificates(self, event):
if self.kube_control.get_ca_certificate():
log.info("CA Certificate is available from kube-control.")
return True

self.unit.status = MaintenanceStatus("Evaluating certificates.")
evaluation = self.certificates.evaluate_relation(event)
if evaluation:
Expand Down Expand Up @@ -192,7 +196,7 @@ def _install_or_upgrade(self, event, config_hash=None):
controller.apply_manifests()
except ManifestClientError as e:
self.unit.status = WaitingStatus("Waiting for kube-apiserver")
log.warn(f"Encountered retryable installation error: {e}")
log.warning("Encountered retryable installation error: %s", e)
event.defer()
return False
return True
Expand Down
13 changes: 11 additions & 2 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,20 @@ def kube_control():
kube_control.get_controller_labels.return_value = []
kube_control.get_cluster_tag.return_value = "kubernetes-4ypskxahbu3rnfgsds3pksvwe3uh0lxt"
kube_control.get_cluster_cidr.return_value = ip_network("192.168.0.0/16")
kube_control.get_ca_certificate.return_value = None
kube_control.relation.app.name = "kubernetes-control-plane"
kube_control.relation.units = [f"kubernetes-control-plane/{_}" for _ in range(2)]
yield kube_control


def test_waits_for_relations(harness):
harness.begin_with_initial_hooks()
charm = harness.charm
assert isinstance(charm.unit.status, BlockedStatus)
assert charm.unit.status.message == "Missing required certificates"


@pytest.mark.usefixtures("kube_control")
def test_waits_for_certificates(harness):
harness.begin_with_initial_hooks()
charm = harness.charm
Expand All @@ -80,8 +89,8 @@ def test_waits_for_certificates(harness):
"easyrsa/0",
yaml.safe_load(Path("tests/data/certificates_data.yaml").read_text()),
)
assert isinstance(charm.unit.status, BlockedStatus)
assert charm.unit.status.message == "Missing required kube-control relation"
assert isinstance(charm.unit.status, MaintenanceStatus)
assert charm.unit.status.message == "Deploying AWS Cloud Provider"


@mock.patch("ops.interface_kube_control.KubeControlRequirer.create_kubeconfig")
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ commands =
description = Check code against coding style standards
deps =
black
flake8 < 5.0 # TODO: https://github.com/csachs/pyproject-flake8/issues/13
flake8
flake8-docstrings
flake8-copyright
flake8-builtins
Expand Down

0 comments on commit a48f7ce

Please sign in to comment.