Skip to content

Commit

Permalink
few clean-ups
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavcracker committed Jan 30, 2025
1 parent 3669383 commit 5deaba7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 5 additions & 5 deletions kubemarine/kubernetes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import re
import json
from contextlib import contextmanager
from typing import List, Dict, Iterator, Any, Optional, Union
from typing import List, Dict, Iterator, Any, Optional

import yaml
from jinja2 import Template
Expand Down Expand Up @@ -399,8 +399,6 @@ def join_control_plane(cluster: KubernetesCluster, node: NodeGroup, join_dict: d
node.sudo("mkdir -p /etc/kubernetes")
node.put(io.StringIO(config), '/etc/kubernetes/join-config.yaml', sudo=True)



# put control-plane patches
components.create_kubeadm_patches_for_node(cluster, node)

Expand Down Expand Up @@ -508,6 +506,7 @@ def init_first_control_plane(group: NodeGroup) -> None:
log.debug("Uploading init config to initial control_plane...")
first_control_plane.sudo("mkdir -p /etc/kubernetes")
first_control_plane.put(io.StringIO(config), '/etc/kubernetes/init-config.yaml', sudo=True)

# put control-plane patches
components.create_kubeadm_patches_for_node(cluster, first_control_plane)

Expand All @@ -516,6 +515,7 @@ def init_first_control_plane(group: NodeGroup) -> None:

# put audit-policy.yaml
prepare_audit_policy(first_control_plane)

log.debug("Initializing first control_plane...")
result = first_control_plane.sudo(
"kubeadm init"
Expand Down Expand Up @@ -1161,6 +1161,7 @@ def images_prepull(group: DeferredGroup, collector: CollectorCallback) -> Token:
config = components.get_kubeadm_config(cluster, kubeadm_init)

group.put(io.StringIO(config), '/etc/kubernetes/prepull-config.yaml', sudo=True)

return group.sudo("kubeadm config images pull --config=/etc/kubernetes/prepull-config.yaml",
pty=True, callback=collector)

Expand Down Expand Up @@ -1289,5 +1290,4 @@ def prepare_audit_policy(group: NodeGroup) -> None:
policy_config_file = yaml.dump(policy_config)
utils.dump_file(cluster, policy_config_file, 'audit-policy.yaml')
# upload rules on cluster
group.put(io.StringIO(policy_config_file), audit_file_name, sudo=True, backup=True)

group.put(io.StringIO(policy_config_file), audit_file_name, sudo=True, backup=True)
3 changes: 3 additions & 0 deletions kubemarine/kubernetes/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ def _upload_config(cluster: KubernetesCluster, control_plane: AbstractGroup[RunR

control_plane.put(io.StringIO(config), remote_path, sudo=True)


def _update_configmap(cluster: KubernetesCluster, control_plane: NodeGroup, configmap: str,
uploader: Callable[[DeferredGroup], None], backup_dir: str) -> bool:
logger = cluster.log
Expand Down Expand Up @@ -894,6 +895,7 @@ def compare_kubelet_config(cluster: KubernetesCluster, *, with_inventory: bool)
def compare_configmap(cluster: KubernetesCluster, configmap: str) -> Optional[str]:
control_plane = cluster.nodes['control-plane'].get_first_member()
kubeadm_config = KubeadmConfig(cluster)

if configmap == 'kubelet-config':
# Do not check kubelet-config ConfigMap, because some properties may be deleted from KubeletConfiguration
# if set to default, for example readOnlyPort: 0, protectKernelDefaults: false
Expand Down Expand Up @@ -959,6 +961,7 @@ def compare_configmap(cluster: KubernetesCluster, configmap: str) -> Optional[st
fromfile=f'{configmap} ConfigMap',
tofile=f"{configmap} ConfigMap merged 'services.{section}' section")


def _detect_changes(logger: log.EnhancedLogger, old: str, new: str, fromfile: str, tofile: str) -> bool:
diff = utils.get_yaml_diff(old, new, fromfile, tofile)
if diff is not None:
Expand Down

0 comments on commit 5deaba7

Please sign in to comment.