Skip to content

Optimize on_secret_create & on_innodbcluster_field_backup_schedules handlers #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
# Copyright (c) 2021, Oracle and/or its affiliates.
#
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
#

#!/bin/bash

docker build --build-arg http_proxy=${http_proxy} --build-arg https_proxy=${https_proxy} --build-arg no_proxy=${no_proxy} -t mysql/mysql-operator:8.0 .
11 changes: 5 additions & 6 deletions docker-build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@

FROM %%MYSQL_OPERATOR_PYTHON_DEPS%%


RUN rpm -U %%MYSQL_REPO_URL%%/mysql80-community-release-el8.rpm \
&& microdnf update && echo "[main]" > /etc/dnf/dnf.conf \
&& microdnf install -y mysql-shell-%%MYSQL_SHELL_VERSION%% \
&& microdnf remove mysql80-community-release \
&& microdnf clean all
RUN rpm -U %%MYSQL_REPO_URL%%/mysql80-community-release-el8.rpm && \
microdnf update && echo "[main]" > /etc/dnf/dnf.conf && \
microdnf install -y mysql-shell-%%MYSQL_SHELL_VERSION%% && \
microdnf remove mysql80-community-release && \
microdnf clean all

RUN groupadd -g27 mysql && useradd -u27 -g27 mysql

Expand Down
4 changes: 1 addition & 3 deletions docker-deps/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ARG PYTHON_BASE_DIR

RUN dnf install -y gcc git tar
COPY ${PYTHON_TARBALL} .
RUN mkdir -p ${PYTHON_BASE_DIR} && cd ${PYTHON_BASE_DIR} && tar xzf /${PYTHON_TARBALL}
RUN mkdir -p ${PYTHON_BASE_DIR} && cd ${PYTHON_BASE_DIR} && tar -xzf /${PYTHON_TARBALL}
ENV PATH=${PYTHON_BASE_DIR}/${PYTHON_ROOT}/bin:$PATH
ENV LD_LIBRARY_PATH=${PYTHON_BASE_DIR}/${PYTHON_ROOT}/lib

Expand All @@ -22,5 +22,3 @@ RUN pip3 install --target=/tmp/site-packages -r requirements.txt
FROM oraclelinux:8-slim

COPY --from=pip-stage /tmp/site-packages /usr/lib/mysqlsh/python-packages


14 changes: 8 additions & 6 deletions mysqloperator/controller/innodbcluster/operator_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,13 @@ def on_innodbcluster_field_router_version(old: str, new: str, body: Body,
router_objects.update_router_image(router_deploy, cluster.parsed_spec, logger)



@kopf.on.field(consts.GROUP, consts.VERSION, consts.INNODBCLUSTER_PLURAL,
field="spec.backupSchedules") # type: ignore
def on_innodbcluster_field_backup_schedules(old: str, new: str, body: Body,
logger: Logger, **kwargs):
logger: Logger, **kwargs):
if old == new:
return

logger.info("on_innodbcluster_field_backup_schedules")
cluster = InnoDBCluster(body)

# Ignore spec changes if the cluster is still being initialized
Expand All @@ -410,8 +408,10 @@ def on_innodbcluster_field_backup_schedules(old: str, new: str, body: Body,
# don't need to take actions in post_create_actions() in the cluster controller
# but async await for Kopf to call again this handler.
if not cluster.get_create_time():
raise kopf.TemporaryError("The cluster is not ready. Will create the schedules once the first instance is up and running", delay=10)
raise kopf.TemporaryError("Cluster is not created or not ready. "
"Will create the schedules once the first instance is up and running", delay=30)

logger.info("on_innodbcluster_field_backup_schedules")
cluster.parsed_spec.validate(logger)
with ClusterMutex(cluster):
backup_objects.update_schedules(cluster.parsed_spec, old, new, logger)
Expand Down Expand Up @@ -605,8 +605,10 @@ def on_pod_delete(body: Body, logger: Logger, **kwargs):
logger.error(f"Owner cluster for {pod.name} does not exist anymore")


@kopf.on.create("", "v1", "secrets") # type: ignore
@kopf.on.update("", "v1", "secrets") # type: ignore
@kopf.on.create("", "v1", "secrets",
field="type", value="kubernetes.io/tls") # type: ignore
@kopf.on.update("", "v1", "secrets",
field="type", value="kubernetes.io/tls") # type: ignore
def on_secret_create(name: str, namespace: str, logger: Logger, **kwargs):
"""
Wait for Secret objects used by clusters for TLS CA and certificate.
Expand Down
6 changes: 4 additions & 2 deletions mysqloperator/sidecar_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,10 @@ def on_tls_secret_create_or_change(value: dict, useSelfSigned: bool, router_depl
raise kopf.PermanentError("Timeout waiting for TLS files to get refreshed")


@kopf.on.create("", "v1", "secrets") # type: ignore
@kopf.on.update("", "v1", "secrets") # type: ignore
@kopf.on.create("", "v1", "secrets",
field="type", value="kubernetes.io/tls") # type: ignore
@kopf.on.update("", "v1", "secrets",
field="type", value="kubernetes.io/tls") # type: ignore
def on_secret_create_or_update(name: str, namespace: str, spec, new, logger: Logger, **kwargs):
global g_cluster_name

Expand Down