Skip to content

Commit

Permalink
Merge pull request #129 from gianlucam76/shard-manifest
Browse files Browse the repository at this point in the history
Autogenerate YAML for deployment for cluster sharding
  • Loading branch information
gianlucam76 committed Oct 24, 2023
2 parents 873e0e2 + 380caca commit c9ac64f
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ manifests: $(CONTROLLER_GEN) $(KUSTOMIZE) $(ENVSUBST) fmt generate ## Generate W
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
MANIFEST_IMG=$(CONTROLLER_IMG)-$(ARCH) MANIFEST_TAG=$(TAG) $(MAKE) set-manifest-image
$(KUSTOMIZE) build config/default | $(ENVSUBST) > manifest/manifest.yaml
./scripts/extract_deployment.sh manifest/manifest.yaml manifest/deployment-shard.yaml

.PHONY: generate
generate: $(CONTROLLER_GEN) ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Expand Down
2 changes: 2 additions & 0 deletions config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ spec:
args:
- "--health-probe-bind-address=:8081"
- "--metrics-bind-address=127.0.0.1:8080"
- "--shard-key="
- "--v=5"
80 changes: 80 additions & 0 deletions manifest/deployment-shard.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
control-plane: sc-manager
name: sc-manager-{{.SHARD}}
namespace: projectsveltos
spec:
replicas: 1
selector:
matchLabels:
control-plane: sc-manager
template:
metadata:
annotations:
kubectl.kubernetes.io/default-container: manager
labels:
control-plane: sc-manager
spec:
containers:
- args:
- --health-probe-bind-address=:8081
- --metrics-bind-address=127.0.0.1:8080
- --shard-key={{.SHARD}}
- --v=5
command:
- /manager
image: projectsveltos/sveltoscluster-manager-amd64:dev
livenessProbe:
httpGet:
path: /healthz
port: 8081
initialDelaySeconds: 15
periodSeconds: 20
name: manager
readinessProbe:
httpGet:
path: /readyz
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
resources:
limits:
cpu: 500m
memory: 128Mi
requests:
cpu: 10m
memory: 64Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
- args:
- --secure-listen-address=0.0.0.0:8443
- --upstream=http://127.0.0.1:8080/
- --logtostderr=true
- --v=0
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.12.0
name: kube-rbac-proxy
ports:
- containerPort: 8443
name: https
protocol: TCP
resources:
limits:
cpu: 500m
memory: 128Mi
requests:
cpu: 5m
memory: 64Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
securityContext:
runAsNonRoot: true
serviceAccountName: sc-manager
terminationGracePeriodSeconds: 10
2 changes: 2 additions & 0 deletions manifest/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ spec:
- args:
- --health-probe-bind-address=:8081
- --metrics-bind-address=127.0.0.1:8080
- --shard-key=
- --v=5
command:
- /manager
image: projectsveltos/sveltoscluster-manager-amd64:dev
Expand Down
48 changes: 48 additions & 0 deletions scripts/extract_deployment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Define the YAML file path
yaml_file=$1
output_file=$2

# Create a temporary directory to store the split sections
mkdir -p temp_yaml_sections

# Initialize variables for section counting and flag to track changes
section_count=0
in_section=false

# Iterate through the YAML file
while IFS= read -r line; do
if [[ $line == '---' ]]; then
# Start a new section
in_section=true
section_count=$((section_count + 1))
current_section_file="temp_yaml_sections/section_${section_count}.yaml"
continue
fi

if [[ $in_section == true ]]; then
# Replace "shard-key=" to contain shard info
if [[ $line == *"shard-key"* ]]; then
line=$(echo "$line" | sed "s/shard-key=/shard-key={{.SHARD}}/")
fi

# Replace "name" to contain shard info
if [[ $line == *"name: sc-manager"* ]]; then
line=$(echo "$line" | sed "s/sc-manager/sc-manager-{{.SHARD}}/")
fi

# Write the line to the current section file
echo "$line" >> "$current_section_file"
fi
done < "$yaml_file"

# Iterate through the split sections and print those with "kind: Deployment"
for section_file in temp_yaml_sections/*.yaml; do
if grep -q "kind: Deployment" "$section_file"; then
cat "$section_file" > $output_file
fi
done

# Remove the temporary directory
rm -r temp_yaml_sections

0 comments on commit c9ac64f

Please sign in to comment.