Skip to content

Commit

Permalink
Merge branch 'main' into merge-main-forward
Browse files Browse the repository at this point in the history
  • Loading branch information
kian99 committed Jul 4, 2023
2 parents ea0af4f + 36c3016 commit cbd413a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ COPY . .
RUN echo "${GIT_COMMIT}" | tee ./version/commit.txt
RUN echo "${VERSION}" | tee ./version/version.txt
RUN --mount=type=ssh source /root/.gvm/scripts/gvm && go mod vendor
RUN --mount=type=ssh source /root/.gvm/scripts/gvm && go build -o jimmsrv -race -v -a -mod vendor ./cmd/jimmsrv
RUN --mount=type=ssh source /root/.gvm/scripts/gvm && go build -tags version -o jimmsrv -v -a -mod vendor ./cmd/jimmsrv

# Define a smaller single process image for deployment
FROM ${DOCKER_REGISTRY}ubuntu:20.04 AS deploy-env
Expand Down
30 changes: 26 additions & 4 deletions charms/jimm-k8s/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def __init__(self, *args):
super().__init__(*args)

self._state = State(self.app, lambda: self.model.get_relation("peer"))
self._unit_state = State(self.unit, lambda: self.model.get_relation("peer"))

self.framework.observe(self.on.peer_relation_changed, self._on_peer_relation_changed)
self.framework.observe(self.on.jimm_pebble_ready, self._on_jimm_pebble_ready)
Expand Down Expand Up @@ -236,6 +237,7 @@ def _update_workload(self, event):
return

self._ensure_bakery_agent_file(event)
self._ensure_vault_file(event)
self._install_dashboard(event)

dns_name = self._get_dns_name(event)
Expand Down Expand Up @@ -313,6 +315,7 @@ def _update_workload(self, event):
else:
logger.info("workload container not ready - defering")
event.defer()
return

dashboard_relation = self.model.get_relation("dashboard")
if dashboard_relation and self.unit.is_leader():
Expand Down Expand Up @@ -416,6 +419,7 @@ def _install_dashboard(self, event):
# this event.
if not container.can_connect():
event.defer()
return

# fetch the resource filename
try:
Expand Down Expand Up @@ -496,10 +500,14 @@ def _on_vault_relation_joined(self, event):
event.relation.data[self.unit]["access_address"] = json.dumps(self._get_network_address(event))
event.relation.data[self.unit]["isolated"] = json.dumps(False)

@requires_state_setter
def _on_vault_relation_changed(self, event):
def _ensure_vault_file(self, event):
container = self.unit.get_container(WORKLOAD_CONTAINER)

if not self._unit_state.is_ready():
logger.info("unit state not ready")
event.defer()
return

# if we can't connect to the container we should defer
# this event.
if not container.can_connect():
Expand All @@ -509,6 +517,16 @@ def _on_vault_relation_changed(self, event):
if container.exists(self._vault_secret_filename):
container.remove_path(self._vault_secret_filename)

secret_data = self._unit_state.vault_secret_data
if secret_data:
self._push_to_workload(self._vault_secret_filename, secret_data, event)

def _on_vault_relation_changed(self, event):
if not self._unit_state.is_ready() or not self._state.is_ready():
logger.info("state not ready")
event.defer()
return

addr = _json_data(event, "vault_url")
if not addr:
return
Expand All @@ -523,9 +541,13 @@ def _on_vault_relation_changed(self, event):
secret["data"]["role_id"] = role_id

secret_data = json.dumps(secret)
self._push_to_workload(self._vault_secret_filename, secret_data, event)

self._state.vault_address = addr
logger.error("setting unit state data {}".format(secret_data))
self._unit_state.vault_secret_data = secret_data
if self.unit.is_leader():
self._state.vault_address = addr

self._update_workload(event)

def _path_exists_in_workload(self, path: str):
"""Returns true if the specified path exists in the
Expand Down
3 changes: 2 additions & 1 deletion charms/jimm-k8s/tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def setUp(self):
self.addCleanup(self.tempdir.cleanup)
self.harness.charm.framework.charm_dir = pathlib.Path(self.tempdir.name)

self.harness.add_relation("peer", "jimm")
jimm_id = self.harness.add_relation("peer", "juju-jimm-k8s")
self.harness.add_relation_unit(jimm_id, "juju-jimm-k8s/1")
self.harness.container_pebble_ready("jimm")

rel_id = self.harness.add_relation("ingress", "nginx-ingress")
Expand Down
5 changes: 5 additions & 0 deletions cmd/jimmsrv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"go.uber.org/zap"

"github.com/CanonicalLtd/jimm"
"github.com/CanonicalLtd/jimm/version"
)

func main() {
Expand All @@ -32,6 +33,10 @@ func main() {

// start initialises the jimmsrv service.
func start(ctx context.Context, s *service.Service) error {
zapctx.Info(ctx, "jimm info",
zap.String("version", version.VersionInfo.Version),
zap.String("commit", version.VersionInfo.GitCommit),
)
if logLevel := os.Getenv("JIMM_LOG_LEVEL"); logLevel != "" {
if err := zapctx.LogLevel.UnmarshalText([]byte(logLevel)); err != nil {
zapctx.Error(ctx, "cannot set log level", zap.Error(err))
Expand Down

0 comments on commit cbd413a

Please sign in to comment.