in mysqloperator/controller/innodbcluster/cluster_objects.py [0:0]
def submit_patches(self) -> None:
self.logger.info(f"InnoDBClusterObjectModifier::submit_patches sts_changed={self.sts_changed} sts_spec_changed={self.sts_spec_changed} len(router_deploy_patch)={len(self.router_deploy_patch)} len(commands)={len(self.commands)}")
if (self.sts_changed or len(self.router_deploy_patch) or len(self.commands)):
if len(self.commands):
for command in self.commands:
command.run(self.logger)
if self.sts_changed:
if self.sts_spec_changed:
# this should apply server_sts_patch over self.sts.spec and empty self.server_sts_patch
# in the next step we will `replace` the STS and not `patch` it
# Only if the self.sts.spec is not touched should be server_sts_patch be applied, as otherwise
# changes to self.sts.spec will be skipped/forgotten
self._apply_server_sts_patch_to_sts_spec_if_needed()
if len(self.server_sts_patch):
self.logger.info(f"Patching STS.spec with {self.server_sts_patch}")
if self.sts_template_changed:
restart_patch = {"spec":{"template":{"metadata":{"annotations":{"kubectl.kubernetes.io/restartedAt":utils.isotime()}}}}}
utils.merge_patch_object(self.server_sts_patch, restart_patch)
api_apps.patch_namespaced_stateful_set(self.sts.metadata.name, self.sts.metadata.namespace, body=self.server_sts_patch)
self.server_sts_patch = {}
else:
self.logger.info(f"Replacing STS.spec with {self.sts.spec}")
# only if template has been changed. It could be that only scale up/down (spec['replica'] changed) has happened
# in that case if we set an annotation in the template the whole STS will be rolled over and this is not
# what is wanted. If replica count is increased only new pods are needed, respectively when replica is decreased.
# if replica is up and we set the annotation actually what will happen is rollover update and then scale up - we disturb the cluster
# (and tests will fail)
if self.sts_template_changed:
if not "annotations" in self.sts.spec["template"]["metadata"] or self.sts.spec["template"]["metadata"]["annotations"] is None:
self.sts.spec["template"]["metadata"]["annotations"] = {}
self.sts.spec["template"]["metadata"]["annotations"]["kubectl.kubernetes.io/restartedAt"] = utils.isotime()
api_apps.replace_namespaced_stateful_set(self.sts.metadata.name, self.sts.metadata.namespace, body=self.sts)
if len(self.router_deploy_patch) and (deploy:= self.cluster.get_router_deployment()):
self.logger.info(f"Patching Deployment with {self.router_deploy_patch}")
router_objects.update_deployment_spec(deploy, self.router_deploy_patch)