Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhanced Synchronization and Configuration Handling in Keess (#30)
# Enhanced Synchronization and Configuration Handling in Keess This pull request introduces significant enhancements to the Keess application, focusing on improving the reliability of secrets and configmaps synchronization across namespaces and Kubernetes clusters. Additionally, it modernizes the CLI experience and optimizes the Docker image for better performance and usability. ## Key Changes ### Switch from Watch to Poll Method - **Issue**: The previous implementation using the Kubernetes API's watch method occasionally missed important events, leading to synchronization gaps. - **Solution**: Transitioned to a polling mechanism using the list method, ensuring comprehensive coverage of all events without missing updates. ### Adoption of Cobra CLI - **Improvement**: Replaced the existing CLI library with [Cobra](https://github.com/spf13/cobra), a widely adopted framework that offers enhanced features and a more standardized command-line experience. - **Benefits**: Provides better support for command structuring, argument parsing, and documentation, making Keess more accessible and easier to use for the community. ### Docker Image Optimization - **Update**: The Docker image has been revised to use a smaller base image, reducing the overall size and improving the startup time of the application. - **Advantage**: Enhances the efficiency of deploying Keess in diverse environments, from development to production, especially in cloud-native ecosystems with resource constraints. ### Helm Chart Adjustments - **Modification**: Updated the Helm chart to accommodate new command-line options introduced by the switch to Cobra and the changes in application configuration. - **Flexibility**: These updates make deploying Keess with Helm more customizable, allowing users to tailor the deployment to their specific needs. ## Command Line Options The new CLI, powered by Cobra, introduces several command line options to enhance flexibility and usability: - `--config`: Specify the configuration file path (default is `$HOME/.keess.yaml`). - `--logLevel`: Set the logging level (e.g., debug, info, warn). - `--localCluster`: Name of the local Kubernetes cluster. - `--kubeConfigPath`: Path to the kubeconfig file for cluster authentication. - `--namespacePollingInterval`: Interval in seconds to poll for namespace changes. - `--pollingInterval`: Interval in seconds to poll for secrets and configmaps. - `--housekeepingInterval`: Interval in seconds for orphan object cleanup. ### Using Command Line Options To use these options, include them when running Keess commands: ```shell keess run --config /your/config/path.yaml --logLevel info ``` ## Implementation Details - **Commands Integration**: Migrated core application logic into Cobra-based commands, enhancing modularity and testability. - **Configuration Management**: Streamlined configuration handling using Viper, supporting both environment variables and configuration files for greater flexibility. - **Logging and Monitoring**: Upgraded logging mechanism for better clarity and troubleshooting support, crucial for maintaining synchronization integrity. ## How to Test 1. Deploy the updated Keess application using the revised Helm chart. 2. Configure synchronization tasks across namespaces and clusters as needed. 3. Change the `test.py` with the correct values for `source_cluster` and `destination_cluster`. 4. Run `make test`. ## Helm diff ```diff Comparing release=keess, chart=keess/keess keess, keess, ClusterRole (rbac.authorization.k8s.io) has changed: # Source: keess/templates/cluster-role.yaml apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: keess labels: - helm.sh/chart: keess-0.2.15 + helm.sh/chart: keess-1.0.0 app.kubernetes.io/name: keess app.kubernetes.io/instance: keess - app.kubernetes.io/version: "0.2.14" + app.kubernetes.io/version: "1.0.0" app.kubernetes.io/managed-by: Helm rules: - apiGroups: [""] resources: - configmaps - secrets verbs: ["get", "create", "update", "patch", "delete", "list", "watch"] - apiGroups: [""] resources: - namespaces verbs: ["get", "list", "watch"] - apiGroups: [""] resources: - nodes verbs: ["list"] - apiGroups: [""] resources: - events verbs: ["create"] keess, keess, ClusterRoleBinding (rbac.authorization.k8s.io) has changed: # Source: keess/templates/cluster-role-binding.yaml apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: keess labels: - helm.sh/chart: keess-0.2.15 + helm.sh/chart: keess-1.0.0 app.kubernetes.io/name: keess app.kubernetes.io/instance: keess - app.kubernetes.io/version: "0.2.14" + app.kubernetes.io/version: "1.0.0" app.kubernetes.io/managed-by: Helm roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: keess subjects: - kind: ServiceAccount name: keess namespace: keess keess, keess, Deployment (apps) has changed: # Source: keess/templates/deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: keess namespace: keess labels: - helm.sh/chart: keess-0.2.15 + helm.sh/chart: keess-1.0.0 app.kubernetes.io/name: keess app.kubernetes.io/instance: keess - app.kubernetes.io/version: "0.2.14" + app.kubernetes.io/version: "1.0.0" app.kubernetes.io/managed-by: Helm spec: selector: matchLabels: app.kubernetes.io/name: keess app.kubernetes.io/instance: keess template: metadata: labels: app.kubernetes.io/name: keess app.kubernetes.io/instance: keess spec: serviceAccountName: keess securityContext: {} volumes: - name: config secret: secretName: keess defaultMode: 420 containers: - name: keess securityContext: {} - image: "image-registry.powerapp.cloud/keess/keess:0.2.14" - env: - - name: KEESS_SOURCE_CONTEXT - value: "app-alpha-gm" - - name: KEESS_DESTINATION_CONTEXTS - value: "app-beta-px" - - name: LOG_LEVEL - value: "DEBUG" + image: "image-registry.powerapp.cloud/keess/keess:PR-30-dac89984ddfead89fc06aafa0e80f0d8c2d4dc6a-1" + args: + - --logLevel=debug + - --localCluster=app-alpha-gm + - --kubeConfigPath=/root/.kube/config + - --pollingInterval=60 + - --namespacePollingInterval=60 + - --housekeepingInterval=60 imagePullPolicy: IfNotPresent volumeMounts: - name: config mountPath: /root/.kube readOnly: true ports: - name: http containerPort: 8080 protocol: TCP livenessProbe: httpGet: path: /health port: http initialDelaySeconds: 60 readinessProbe: httpGet: path: /health port: http resources: limits: ephemeral-storage: 150Mi memory: 128Mi requests: cpu: 100m ephemeral-storage: 150Mi memory: 64Mi keess, keess, Secret (v1) has changed: # Source: keess/templates/secret.yaml apiVersion: v1 kind: Secret metadata: labels: app.kubernetes.io/instance: keess app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: keess - app.kubernetes.io/version: 0.2.14 - helm.sh/chart: keess-0.2.15 + app.kubernetes.io/version: 1.0.0 + helm.sh/chart: keess-1.0.0 name: keess namespace: keess data: config: 'REDACTED # (7651 bytes)' keess, keess, ServiceAccount (v1) has changed: # Source: keess/templates/serviceaccount.yaml apiVersion: v1 kind: ServiceAccount metadata: name: keess namespace: keess labels: - helm.sh/chart: keess-0.2.15 + helm.sh/chart: keess-1.0.0 app.kubernetes.io/name: keess app.kubernetes.io/instance: keess - app.kubernetes.io/version: "0.2.14" + app.kubernetes.io/version: "1.0.0" app.kubernetes.io/managed-by: Helm ``` ## Test execution result ``` log -- /Users/marcusvinicius.leandro/Source/keess/test.py [INFO] Deleted destination namespace 'test-namespace-dest-1'. [INFO] Deleted destination namespace 'test-namespace-dest-2'. [INFO] Created source namespace 'test-namespace'. [INFO] Created destination namespace 'test-namespace-dest-1' with label 'keess.powerhrg.com/testing=yes'. [INFO] Created destination namespace 'test-namespace-dest-2' with label 'keess.powerhrg.com/testing=yes'. [INFO] Created secret 'new-test-secret' in source namespace 'test-namespace'. [INFO] Created ConfigMap 'new-test-configmap' in source namespace 'test-namespace'. [INFO] Waiting for resources to be created... [INFO] Applied labels and annotations to secret 'new-test-secret' in namespace 'test-namespace'. [INFO] Applied labels and annotations to configmap 'new-test-configmap' in namespace 'test-namespace'. [INFO] Waiting for synchronization to complete... [SUCCESS] Secret 'new-test-secret' in namespace 'test-namespace-dest-1' has been verified successfully with all annotations. [SUCCESS] Configmap 'new-test-configmap' in namespace 'test-namespace-dest-1' has been verified successfully with all annotations. [SUCCESS] Secret 'new-test-secret' in namespace 'test-namespace-dest-2' has been verified successfully with all annotations. [SUCCESS] Configmap 'new-test-configmap' in namespace 'test-namespace-dest-2' has been verified successfully with all annotations. [INFO] Applied labels and annotations to secret 'new-test-secret' in namespace 'test-namespace'. [INFO] Applied labels and annotations to configmap 'new-test-configmap' in namespace 'test-namespace'. [INFO] Waiting for synchronization to matching namespaces... [SUCCESS] Secret 'new-test-secret' in namespace 'test-namespace-dest-1' has been verified successfully with all annotations. [SUCCESS] Configmap 'new-test-configmap' in namespace 'test-namespace-dest-1' has been verified successfully with all annotations. [SUCCESS] Secret 'new-test-secret' in namespace 'test-namespace-dest-2' has been verified successfully with all annotations. [SUCCESS] Configmap 'new-test-configmap' in namespace 'test-namespace-dest-2' has been verified successfully with all annotations. [INFO] Test scenario 3 completed. [INFO] Applied labels and annotations to secret 'new-test-secret' in namespace 'test-namespace'. [INFO] Applied labels and annotations to configmap 'new-test-configmap' in namespace 'test-namespace'. [INFO] Labels and annotations applied for cross-cluster synchronization. Waiting for synchronization to complete... [SUCCESS] Secret 'new-test-secret' in namespace 'test-namespace' has been verified successfully with all annotations. [SUCCESS] Configmap 'new-test-configmap' in namespace 'test-namespace' has been verified successfully with all annotations. [INFO] Test scenario 4 completed. [INFO] Deleted secret 'new-test-secret' in source namespace 'test-namespace'. [INFO] Deleted configmap 'new-test-configmap' in source namespace 'test-namespace'. [INFO] Deleted source namespace 'test-namespace'. [INFO] Deleted destination namespace 'test-namespace-dest-1'. [INFO] Deleted destination namespace 'test-namespace-dest-2'. ``` ## Conclusion These improvements make Keess a more reliable and user-friendly tool for Kubernetes configuration management. By addressing previous limitations and leveraging more robust technologies, we're setting the stage for more scalable and secure infrastructure management practices. --------- Signed-off-by: Igor Valente Blackman <[email protected]> Co-authored-by: Igor Blackman <[email protected]>
- Loading branch information