### Defining a Simple KCL Sidecar Configuration Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL example illustrates the definition of a `SimpleSidecar` container. It specifies the sidecar's name as 'test' and its version as 'v1.2.3'. This snippet showcases a basic configuration for a sidecar that is expected to run on the host. ```KCL import models.kube.frontend.sidecar as s sidecar = s.SimpleSidecar { name = "test" version = "v1.2.3" } ``` -------------------------------- ### Enabling Namespace Creation with NamespaceMixin in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL example demonstrates how to activate automatic namespace creation for an application. By setting needNamespace to True within the app configuration, the NamespaceMixin handles the underlying logic for provisioning the required Kubernetes namespace. ```KCL app = { needNamespace = True } ``` -------------------------------- ### Defining a Main Container with Liveness Probe in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL example illustrates how to configure a `Main` container, which represents the primary container expected to run on a host. It sets the container's `name` and defines a `livenessProbe` using an HTTP handler to check the container's health at a specified path and initial delay. This snippet depends on `models.kube.frontend.container` and `models.kube.frontend.container.probe`. ```KCL import models.kube.frontend.container import models.kube.frontend.container.probe as p main = container.Main { name = "test" livenessProbe = p.Probe { handler = p.Http { path = "/healthz" } initialDelaySeconds = 10 } } ``` -------------------------------- ### Viewing Konfig Directory Structure (Bash) Source: https://github.com/kcl-lang/konfig/blob/main/README.md This snippet displays the hierarchical directory structure of the Konfig project. It outlines the main folders including `examples`, `models` (with subdirectories like `commons`, `kube`, and `metadata`), and key project files such as `LICENSE`, `Makefile`, `README.md`, `kcl.mod`, and `kcl.mod.lock`. This structure helps users understand where different components and models are located within the repository. ```bash . ├── LICENSE ├── Makefile ├── README-zh.md ├── README.md ├── examples # konfig examples ├── kcl.mod # konfig package metadata file ├── kcl.mod.lock # konfig package metadata lock file └── models ├── commons # Common models ├── kube # Cloud-native resource core models │ ├── backend # Back-end models │ ├── frontend # Front-end models │ │ ├── common # Common front-end models │ │ ├── configmap # ConfigMap │ │ ├── container # Container │ │ ├── ingress # Ingress │ │ ├── resource # Resource │ │ ├── secret # Secret │ │ ├── service # Service │ │ ├── sidecar # Sidecar │ │ ├── strategy # strategy │ │ ├── volume # Volume │ │ └── server.k # The `Server` model │ ├── metadata # Kubernetes metadata │ ├── mixins # Mixin │ ├── render # Front-to-back-end renderers. │ ├── templates # Data template │ └── utils └── metadata # Common metadata ``` -------------------------------- ### Configuring Kubernetes Ingress with KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL snippet demonstrates how to define a Kubernetes Ingress resource. It configures an Ingress named "example-ingress" with a rule for "your-domain.com" routing traffic from "/apple" to "app-service" on port 5678. It also includes TLS configuration for the domain, referencing a secret named "example-ingress-tls". This example illustrates the practical application of the Ingress attributes described previously. ```KCL ingress.Ingress { name = "example-ingress" rules = [ { host = "your-domain.com" http.paths = [ { path = "/apple" pathType = "Prefix" backend.service: { name = "app-service" port.number = 5678 } } ] } ] tls = [ { hosts = ["your-domain.com"] secretName = "example-ingress-tls" } ] } ``` -------------------------------- ### Defining a Kubernetes Job in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL code snippet illustrates how to define a Kubernetes Job resource using the `models.kube.frontend` module. It specifies the `mainContainer` with a name and a command to execute, and sets the container `image`. This example demonstrates a simple Job that runs a Perl script to calculate pi. ```KCL import models.kube.frontend jobConfiguration: frontend.Job { # main container mainContainer = container.Main { name = "pi" command = ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"] } image = "perl" } ``` -------------------------------- ### Configuring PreStop Lifecycle Hook with Exec Command in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL example demonstrates how to define a preStop lifecycle hook for a container using an Exec action. The preStop hook executes a command before the container is terminated, in this case, a timeout command with a shell script. It imports lifecycle and probe models to construct the Lifecycle object. ```KCL import models.kube.frontend.container.lifecycle as lc import models.kube.frontend.container.probe as p p = lc.Lifecycle { preStop = p.Exec { command = [ "timeout" ,"--signal=9" ,"1800s" ,"sh" ,"-c" ,"bash -x /tmp/image-builder/boot/boot.sh" ] } } ``` -------------------------------- ### Configuring HTTP Health Probe in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL snippet demonstrates how to define a `Probe` object for a container. It configures an HTTP handler for the probe, specifying the `/healthz` path to check. Additionally, it sets an `initialDelaySeconds` of 10, meaning the health check will begin 10 seconds after the container starts. This ensures the container has time to initialize before being probed. ```KCL import models.kube.frontend.container.probe as p probe = p.Probe { handler = p.Http { path = "/healthz" } initialDelaySeconds = 10 } ``` -------------------------------- ### Defining a Kubernetes Service Resource in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL code snippet demonstrates how to define a Kubernetes Service resource. It sets the service's name and namespace, applies a 'dev' environment label, and configures two ports: 'grpc-xds' on 15010 and 'https-xds' on 15011. This example illustrates basic service configuration for network exposure. ```KCL service = Service { name = "my-service-name" namespace = "my-service-name" labels.env = "dev" ports = [ { name = "grpc-xds" port = 15010 } { name = "https-xds" port = 15011 } ] } ``` -------------------------------- ### Creating a Kubernetes Secret in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL example illustrates how to define a Kubernetes 'Secret' object. It sets the secret's name, namespace, and 'data' field, which contains key-value pairs of sensitive information. The '$type' attribute is also used to specify the secret's type, facilitating programmatic handling. ```KCL secret = Secret { name = "my-secret" namespace = "my-secret-namespace" data = { foo = bar bar = foo } $type = "kubernetes.io/service-account-token" } ``` -------------------------------- ### Defining a Container Port in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL example illustrates how to define a ContainerPort object. It specifies the port's name as "test", sets the protocol to "TCP", and assigns the container port number to 8080, making it accessible for network communication. ```KCL p = ContainerPort { name = "test" protocol = "TCP" containerPort = 8080 } ``` -------------------------------- ### Configuring a KCL Frontend Server Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL snippet demonstrates how to define an `appConfiguration` for a `frontend.Server`. It configures the `mainContainer` with a specific name, environment variables, and port. Additionally, it sets `selector` and `podMetadata.labels` for proper pod selection and applies a `tiny` resource scheduling strategy. ```KCL import models.kube.frontend import models.kube.frontend.container import models.kube.templates.resource as res_tpl appConfiguration: frontend.Server { mainContainer = container.Main { name = "php-redis" env: { "GET_HOSTS_FROM": {value = "dns"} } ports = [{containerPort = 80}] } selector = { tier = "frontend" } podMetadata.labels: { tier = "frontend" } schedulingStrategy.resource = res_tpl.tiny } ``` -------------------------------- ### Configuring KCL Sidecar with Liveness Probe Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL snippet demonstrates how to define a `Sidecar` container configuration. It sets the container's name to 'test' and configures a `livenessProbe` using an HTTP handler that checks the '/healthz' path after an initial delay of 10 seconds. This ensures the container's health is monitored. ```KCL import models.kube.frontend.sidecar as s import models.kube.frontend.container.probe as p sidecar = s.Sidecar { name = "test" livenessProbe = p.Probe { handler = p.Http { httpPath = "/healthz" } initialDelaySeconds = 10 } } ``` -------------------------------- ### Parsing Scheduling Resource Items in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL snippet defines how individual resource items (CPU, memory, disk) are parsed from a list of strings. It extracts 'requests' and 'limits' values by splitting the string based on '=' or '<' delimiters and stripping whitespace. The output is a list of dictionaries, each representing a resource type with its parsed requests and limits. ```KCL [{ cpu = { requests = (item.split("=")?[1] if len(item.split("=")) > 1 else item.split("<")?[0])?.strip() limits = (item.split("=")?[1] if len(item.split("=")) > 1 else item.split("<")?[-1])?.strip() } } if "cpu" in item else ({ memory = { requests = (item.split("=")?[1] if len(item.split("=")) > 1 else item.split("<")?[0])?.strip() limits = (item.split("=")?[1] if len(item.split("=")) > 1 else item.split("<")?[-1])?.strip() } } if "memory" in item else ({ disk = { requests = (item.split("=")?[1] if len(item.split("=")) > 1 else item.split("<")?[0])?.strip() limits = (item.split("=")?[1] if len(item.split("=")) > 1 else item.split("<")?[-1])?.strip() } } if "disk" in item else Undefined)) for item in schedulingResourceItems] ``` -------------------------------- ### Mapping ServerBackend Workload to Kubernetes Resources in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL snippet defines the default mapping for the `kubernetes` attribute within the ServerBackend configuration. It conditionally includes `_workloadInstance` (Deployment or StatefulSet) and `_headlessServiceInstance` in the resource mapping based on their existence. ```KCL { if _workloadInstance: "${typeof(_workloadInstance)}" = [_workloadInstance] if _headlessServiceInstance: "${typeof(_headlessServiceInstance)}" = [_headlessServiceInstance] } ``` -------------------------------- ### Splitting Resource String into Items in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL snippet defines how a raw resource string is split into individual items. It attempts to split 'resourceStr' by commas; if 'resourceStr' is null or undefined, it defaults to an empty list. This prepares the input for further parsing of individual resource components. ```KCL resourceStr?.split(",") or [] ``` -------------------------------- ### Consolidating Resource Requirements in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL snippet defines the logic for consolidating various forms of resource input (raw string, structured requirements, or simple resource object) into a standardized 'requests' and 'limits' dictionary. It prioritizes inputs, extracting CPU, memory, and ephemeral storage values, with 'Undefined' as a fallback for missing values. The output is a dictionary representing the final resource requirements. ```KCL { requests = { cpu = [r?.cpu?.requests for r in resource if r?.cpu?.requests]?[-1] or Undefined memory = [r?.memory?.requests for r in resource if r?.memory?.requests]?[-1] or Undefined "ephemeral-storage" = [r?.disk?.requests for r in resource if r?.disk?.requests]?[-1] or Undefined } limits = { cpu = [r?.cpu?.limits for r in resource if r?.cpu?.limits]?[-1] or Undefined memory = [r?.memory?.limits for r in resource if r?.memory?.limits]?[-1] or Undefined "ephemeral-storage" = [r?.disk?.limits for r in resource if r?.disk?.limits]?[-1] or Undefined } } if resourceStr else { requests = { cpu = str(resourceRequirementsUnit.requests.cpu) memory = str(resourceRequirementsUnit.requests.memory) "ephemeral-storage" = str(resourceRequirementsUnit.requests.disk) if resourceRequirementsUnit.requests.disk else Undefined } limits = { cpu = str(resourceRequirementsUnit.limits.cpu) memory = str(resourceRequirementsUnit.limits.memory) "ephemeral-storage" = str(resourceRequirementsUnit.limits.disk) if resourceRequirementsUnit.limits.disk else Undefined } } if resourceRequirementsUnit else { requests = { cpu = str(resourceUnit.cpu) memory = str(resourceUnit.memory) "ephemeral-storage" = str(resourceUnit.disk) if resourceUnit.disk else Undefined } limits = { cpu = str(resourceUnit.cpu) memory = str(resourceUnit.memory) "ephemeral-storage" = str(resourceUnit.disk) if resourceUnit.disk else Undefined } } ``` -------------------------------- ### Mapping Job Instance to Kubernetes Resources in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL snippet defines the default mapping for the `kubernetes` attribute within the Job configuration. It specifies that the `_jobInstance` (presumably a KCL object representing a Kubernetes Job) should be included in the resource mapping under its type. ```KCL { "${typeof(_jobInstance)}" = [_jobInstance] } ``` -------------------------------- ### Defining Kubernetes Resource Requirements in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This snippet demonstrates how to define Kubernetes compute resource requirements using the KCL `Resource` model. It imports the necessary module and instantiates a `Resource` object, setting specific values for CPU, memory, and disk, which are crucial for container configuration. ```KCL import models.kube.frontend.resource as res res = res.Resource { cpu = 2 memory = 2048Mi disk = 20Gi } ``` -------------------------------- ### Defining Kubernetes Resource Requirements in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL snippet demonstrates how to define resource requirements for a Kubernetes container using the 'ResourceRequirements' model. It specifies both 'limits' (maximum allowed resources) and 'requests' (minimum required resources) for CPU, memory, and disk, aligning with Kubernetes concepts for managing compute resources. ```KCL import models.kube.frontend.resource as res res = res.ResourceRequirements { limits = { cpu = 1 memory = 1Gi disk = 20Gi } requests = { cpu = 500m memory = 512Mi disk = 10Gi } } ``` -------------------------------- ### Defining Application Labels for ServerBackend in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL snippet sets the default value for `_applicationLabel`, which is a dictionary used to apply standard Kubernetes labels to resources managed by ServerBackend. It specifically sets the 'app.k8s.io/component' label based on the `workloadName`. ```KCL { "app.k8s.io/component": workloadName } ``` -------------------------------- ### Creating a Kubernetes ConfigMap in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL snippet demonstrates how to define a Kubernetes ConfigMap resource. It specifies the `name` and `namespace` for the ConfigMap, along with arbitrary `data` as key-value pairs. ConfigMaps are used to store non-confidential data in key-value pairs. ```KCL configmap = ConfigMap { name = "my-configmap" namespace = "my-configmap-namespace" data = { foo = "bar" bar = "foo" } } ``` -------------------------------- ### Defining Workload Attributes for ServerBackend in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL snippet defines the default structure for `workloadAttributes` used to configure Kubernetes Deployments or StatefulSets managed by ServerBackend. It includes metadata, replica count, selector logic (built-in or custom), pod template definition (labels, containers, init containers, volumes, service account, affinity), and deployment strategy. ```KCL { metadata = utils.MetadataBuilder(config) | { name = workloadName namespace = workloadNamespace } spec = { replicas = config.replicas if config.useBuiltInSelector: selector: {matchLabels: app.selector | config.selector | _applicationLabel} else: selector: {matchLabels: config.selector} template = { metadata = { if config.useBuiltInLabels: labels = app.labels | _applicationLabel **config.podMetadata } spec = { containers = [mainContainer] + (sidecarContainers or []) initContainers = initContainers if config.volumes: volumes = [utils.to_kube_volume(v) for v in config.volumes if v.volumeSource] if config.serviceAccount: serviceAccountName = config.serviceAccount.name if config.affinity: affinity = config.affinity } } if config.deploymentStrategy: strategy = config.deploymentStrategy } } ``` -------------------------------- ### Defining Job Attributes in KCL Konfig Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL snippet defines the default structure for `jobAttrs`, which are used to configure a Kubernetes Job resource. It includes metadata like name and namespace, and spec details such as active deadline, backoff limit, parallelism, and template for pod definition including containers, init containers, restart policy, volumes, and service account. ```KCL { metadata = utils.MetadataBuilder(config) | { name = jobName namespace = jobNamespace } spec = { activeDeadlineSeconds = config.activeDeadlineSeconds backoffLimit = config.backoffLimit completionMode = config.completionMode completions = config.completions manualSelector = config.manualSelector parallelism = config.parallelism suspend = config.suspend ttlSecondsAfterFinished = config.ttlSecondsAfterFinished selector: {matchLabels = app.selector | config.selector} template = { metadata = { labels = app.labels **config.podMetadata } spec = { containers = [ mainContainer *sidecarContainers ] initContainers = initContainers restartPolicy = config.restartPolicy if config.volumes: volumes = [utils.to_kube_volume(v) for v in config.volumes if v.volumeSource] if config.serviceAccount: serviceAccountName = config.serviceAccount.name } } } } ``` -------------------------------- ### Defining a Kubernetes Volume with Secret Source in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL snippet illustrates the creation of a Kubernetes Volume resource. It configures a volume named "kubeconfig" that retrieves its content from a Secret also named "kubeconfig", setting the default file mode to 420. Additionally, it defines a Mount point for this volume at /etc/kubernetes/kubeconfig within a container, specifying it as read-only. ```KCL volume = v.Volume { name = "kubeconfig" volumeSource = v.Secret { secretName = "kubeconfig" defaultMode = 420 } mounts = [ v.Mount { path = "/etc/kubernetes/kubeconfig" readOnly = true } ] } ``` -------------------------------- ### KCL Metadata Object Structure Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL snippet defines a common metadata object structure used across Kubernetes resources. It includes fields for name (converted to lowercase), annotations, namespace, and labels, which are typically passed as parameters to populate the metadata of a Kubernetes object. ```KCL { name: name?.lower() annotations: annotations namespace: namespace labels: labels } ``` -------------------------------- ### Defining Kubernetes ClusterRoleBinding in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL snippet defines the structure for a Kubernetes ClusterRoleBinding object, mapping its attributes like metadata, subjects, and roleRef to corresponding KCL variables. It represents the default KCL construction for a ClusterRoleBinding, used to grant permissions defined by a ClusterRole to subjects. ```KCL rbacv1.ClusterRoleBinding { metadata = metadata subjects = subjects roleRef = roleRef } ``` -------------------------------- ### Defining Kubernetes ClusterRole in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL snippet defines the structure for a Kubernetes ClusterRole object, mapping its attributes like metadata, rules, and aggregationRule to corresponding KCL variables. It represents the default KCL construction for a ClusterRole, typically used within a KCL schema or configuration. ```KCL rbacv1.ClusterRole { metadata = metadata rules = rules aggregationRule = aggregationRule } ``` -------------------------------- ### Type Casting to Resource in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL expression attempts to cast the 'resourcePara' variable to a 'res.Resource' type if its current type matches 'Resource'. If the type does not match, it defaults to 'None'. This provides a mechanism to handle resource objects directly. ```KCL resourcePara as res.Resource if typeof(resourcePara) == "Resource" else None ``` -------------------------------- ### Type Casting to ResourceRequirements in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL expression attempts to cast the 'resourcePara' variable to a 'res.ResourceRequirements' type if its current type matches 'ResourceRequirements'. If the type does not match, it defaults to 'None'. This ensures type safety and provides a fallback for resource requirement objects. ```KCL resourcePara as res.ResourceRequirements if typeof(resourcePara) == "ResourceRequirements" else None ``` -------------------------------- ### Type Casting to String in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL expression attempts to cast the 'resourcePara' variable to a string type if its current type is 'str'. If the type does not match, it defaults to 'None'. This is used for flexible input handling where a resource might be provided as a raw string. ```KCL resourcePara as str if typeof(resourcePara) == "str" else None ``` -------------------------------- ### Defining a Kubernetes ServiceAccount in KCL Source: https://github.com/kcl-lang/konfig/blob/main/docs/konfig.md This KCL snippet defines a Kubernetes ServiceAccount resource. It specifies the account's name and namespace, applies labels for organization, and configures image pull secrets and general secrets that pods using this service account can access. This is crucial for managing pod identities and access to private image registries or sensitive data. ```KCL my_service_account = ServiceAccount { name: "my-service-account" namespace = "my-service-account-namespace" labels: { tier: "monitoring" } imagePullSecrets: [ { name: "my-secret" } ] secrets: [ { name: "my-secret" } ] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.