Skip to content

Commit

Permalink
Merge pull request #107 from canonical/DPE-5401/keeping_pipelines_ope…
Browse files Browse the repository at this point in the history
…nsearch_v214_until_uprade

[DPE-5401] Keeping pipelines opensearch v214 until upgrade
  • Loading branch information
juditnovak authored Sep 9, 2024
2 parents 98686b2 + ac12f24 commit b23b4e8
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
- .
- tests/integration/application-charm
name: Build charm
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v17.0.1
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v21.0.1
with:
path-to-charm-directory: ${{ matrix.path }}
cache: true
Expand All @@ -80,7 +80,7 @@ jobs:
- lint
- unit-test
- build
uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v17.0.1
uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v21.0.1
with:
artifact-prefix: packed-charm-cache-true
cloud: lxd
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ jobs:

build:
name: Build charm
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v16.7.0
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v21.0.1

release:
name: Release charm
needs:
- ci-tests
- build
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v16.7.0
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v21.0.1
with:
channel: 2/edge
artifact-prefix: ${{ needs.build.outputs.artifact-prefix }}
Expand Down
67 changes: 49 additions & 18 deletions lib/charms/tls_certificates_interface/v3/tls_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ def _on_all_certificates_invalidated(self, event: AllCertificatesInvalidatedEven
ModelError,
Relation,
RelationDataContent,
Secret,
SecretNotFoundError,
Unit,
)
Expand All @@ -317,7 +318,7 @@ def _on_all_certificates_invalidated(self, event: AllCertificatesInvalidatedEven

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 17
LIBPATCH = 19

PYDEPS = ["cryptography", "jsonschema"]

Expand Down Expand Up @@ -735,16 +736,16 @@ def calculate_expiry_notification_time(
"""
if provider_recommended_notification_time is not None:
provider_recommended_notification_time = abs(provider_recommended_notification_time)
provider_recommendation_time_delta = (
expiry_time - timedelta(hours=provider_recommended_notification_time)
provider_recommendation_time_delta = expiry_time - timedelta(
hours=provider_recommended_notification_time
)
if validity_start_time < provider_recommendation_time_delta:
return provider_recommendation_time_delta

if requirer_recommended_notification_time is not None:
requirer_recommended_notification_time = abs(requirer_recommended_notification_time)
requirer_recommendation_time_delta = (
expiry_time - timedelta(hours=requirer_recommended_notification_time)
requirer_recommendation_time_delta = expiry_time - timedelta(
hours=requirer_recommended_notification_time
)
if validity_start_time < requirer_recommendation_time_delta:
return requirer_recommendation_time_delta
Expand Down Expand Up @@ -1448,18 +1449,33 @@ def _revoke_certificates_for_which_no_csr_exists(self, relation_id: int) -> None
Returns:
None
"""
provider_certificates = self.get_provider_certificates(relation_id)
requirer_csrs = self.get_requirer_csrs(relation_id)
provider_certificates = self.get_unsolicited_certificates(
relation_id=relation_id
)
for provider_certificate in provider_certificates:
self.on.certificate_revocation_request.emit(
certificate=provider_certificate.certificate,
certificate_signing_request=provider_certificate.csr,
ca=provider_certificate.ca,
chain=provider_certificate.chain,
)
self.remove_certificate(certificate=provider_certificate.certificate)

def get_unsolicited_certificates(
self, relation_id: Optional[int] = None
) -> List[ProviderCertificate]:
"""Return provider certificates for which no certificate requests exists.
Those certificates should be revoked.
"""
unsolicited_certificates: List[ProviderCertificate] = []
provider_certificates = self.get_provider_certificates(relation_id=relation_id)
requirer_csrs = self.get_requirer_csrs(relation_id=relation_id)
list_of_csrs = [csr.csr for csr in requirer_csrs]
for certificate in provider_certificates:
if certificate.csr not in list_of_csrs:
self.on.certificate_revocation_request.emit(
certificate=certificate.certificate,
certificate_signing_request=certificate.csr,
ca=certificate.ca,
chain=certificate.chain,
)
self.remove_certificate(certificate=certificate.certificate)
unsolicited_certificates.append(certificate)
return unsolicited_certificates

def get_outstanding_certificate_requests(
self, relation_id: Optional[int] = None
Expand Down Expand Up @@ -1877,8 +1893,7 @@ def _on_relation_changed(self, event: RelationChangedEvent) -> None:
"Removing secret with label %s",
f"{LIBID}-{csr_in_sha256_hex}",
)
secret = self.model.get_secret(
label=f"{LIBID}-{csr_in_sha256_hex}")
secret = self.model.get_secret(label=f"{LIBID}-{csr_in_sha256_hex}")
secret.remove_all_revisions()
self.on.certificate_invalidated.emit(
reason="revoked",
Expand Down Expand Up @@ -1966,9 +1981,10 @@ def _on_secret_expired(self, event: SecretExpiredEvent) -> None:
Args:
event (SecretExpiredEvent): Juju event
"""
if not event.secret.label or not event.secret.label.startswith(f"{LIBID}-"):
csr = self._get_csr_from_secret(event.secret)
if not csr:
logger.error("Failed to get CSR from secret %s", event.secret.label)
return
csr = event.secret.get_content()["csr"]
provider_certificate = self._find_certificate_in_relation_data(csr)
if not provider_certificate:
# A secret expired but we did not find matching certificate. Cleaning up
Expand Down Expand Up @@ -2008,3 +2024,18 @@ def _find_certificate_in_relation_data(self, csr: str) -> Optional[ProviderCerti
continue
return provider_certificate
return None

def _get_csr_from_secret(self, secret: Secret) -> str:
"""Extract the CSR from the secret label or content.
This function is a workaround to maintain backwards compatiblity
and fix the issue reported in
https://github.com/canonical/tls-certificates-interface/issues/228
"""
if not (csr := secret.get_content().get("csr", "")):
# In versions <14 of the Lib we were storing the CSR in the label of the secret
# The CSR now is stored int the content of the secret, which was a breaking change
# Here we get the CSR if the secret was created by an app using libpatch 14 or lower
if secret.label and secret.label.startswith(f"{LIBID}-"):
csr = secret.label[len(f"{LIBID}-") :]
return csr
4 changes: 3 additions & 1 deletion tests/integration/ha/test_network_cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ async def test_build_and_deploy(ops_test: OpsTest):
# Opensearch
await ops_test.model.set_config(OPENSEARCH_CONFIG)
# NOTE: can't access 2/stable from the tests, only 'edge' available
await ops_test.model.deploy(OPENSEARCH_APP_NAME, channel="2/edge", num_units=NUM_UNITS_DB)
await ops_test.model.deploy(
OPENSEARCH_APP_NAME, channel="2/edge", num_units=NUM_UNITS_DB, revision=143
)

config = {"ca-common-name": "CN_CA"}
await ops_test.model.deploy(TLS_CERT_APP_NAME, channel="stable", config=config)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/ha/test_scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def test_build_and_deploy(ops_test: OpsTest):
# Opensearch
await ops_test.model.set_config(OPENSEARCH_CONFIG)
# NOTE: can't access 2/stable from the tests, only 'edge' available
await ops_test.model.deploy(OPENSEARCH_APP_NAME, channel="2/edge", num_units=2)
await ops_test.model.deploy(OPENSEARCH_APP_NAME, channel="2/edge", num_units=2, revision=143)

config = {"ca-common-name": "CN_CA"}
await ops_test.model.deploy(TLS_CERTIFICATES_APP_NAME, channel="stable", config=config)
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ async def test_build_and_deploy(ops_test: OpsTest):
config = {"ca-common-name": "CN_CA"}
await asyncio.gather(
ops_test.model.deploy(COS_AGENT_APP_NAME, num_units=1),
ops_test.model.deploy(OPENSEARCH_APP_NAME, channel="2/edge", num_units=NUM_UNITS_DB),
ops_test.model.deploy(
OPENSEARCH_APP_NAME, channel="2/edge", num_units=NUM_UNITS_DB, revision=143
),
ops_test.model.deploy(TLS_CERTIFICATES_APP_NAME, channel="stable", config=config),
ops_test.model.deploy(application_charm_build, application_name=DB_CLIENT_APP_NAME),
)
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ async def test_build_and_deploy(ops_test: OpsTest):
pytest.charm = await ops_test.build_charm(".")
await ops_test.model.deploy(pytest.charm, application_name=APP_NAME, num_units=NUM_UNITS_APP)
await ops_test.model.set_config(OPENSEARCH_CONFIG)
await ops_test.model.deploy(OPENSEARCH_APP_NAME, channel="2/edge", num_units=NUM_UNITS_DB)
await ops_test.model.deploy(
OPENSEARCH_APP_NAME, channel="2/edge", num_units=NUM_UNITS_DB, revision=143
)

config = {"ca-common-name": "CN_CA"}
await ops_test.model.deploy(TLS_CERTIFICATES_APP_NAME, channel="stable", config=config)
Expand Down

0 comments on commit b23b4e8

Please sign in to comment.