Git Product home page Git Product logo

konfig's Introduction

Konfig

FOSSA Status

English | Chinese

Konfig is the repository of the infra configuration in KCL.

Konfig provides users with an out-of-the-box, highly abstract configuration interface. The original starting point of the model library is to improve the efficiency and experience of YAML users. We hope to simplify the writing of user-side configuration code by abstracting and encapsulating the model with more complex code into a unified model.

For more details, please refer to: Model Overview

Directory Structure

The overall structure of the configuration library is as follows:

.
├── 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

Prerequisites

Install KCL

Quick Start

See here

License

Apache License Version 2.0

FOSSA Status

konfig's People

Contributors

peefy avatar howieyuen avatar liu-hm19 avatar amyxia1994 avatar sparkyuan avatar markliby avatar he1pa avatar healthjyk avatar chai2010 avatar xyctruth avatar elliotxx avatar leoliuyan avatar riven-blade avatar fossabot avatar jakezhu9 avatar ldxdl avatar

Stargazers

 avatar waiting avatar  avatar  avatar George Kontridze avatar  avatar

Watchers

Chris Aniszczyk avatar  avatar  avatar  avatar

konfig's Issues

[Doc] How to use `env`?

Bug Report

konfig.md 如下:

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 = [
            {
                name = "GET_HOSTS_FROM"
                value = "dns"
            }
        ]
        ports = [{containerPort = 80}]
    }
    selector = {
        tier = "frontend"
    }
    podMetadata.labels: {
        tier = "frontend"
    }
    schedulingStrategy.resource = res_tpl.tiny
}

但是实际执行报错:

expected EnvMap, got [{str(name) | str(value):str(GET_HOSTS_FROM) | str(dns)}](TypeError)
container.k(68, 5): variable is defined here, its type is EnvMap, but got [{str(name) | str(value):str(GET_HOSTS_FROM) | str(dns)}]

1. Minimal reproduce step (Required)

如上

2. What did you expect to see? (Required)

按照文档可以正确使用

3. What did you see instead (Required)

如上

4. What is your KCL components version? (Required)

  1. kcl 0.9.0 beta
  2. konfig 0.5.0

How to add `ClusterRoleBinding` with `konfig`?

General Question

I have read the documentation and did not find an answer.

How can I use Attributes, such as ClusterRole ClusterRoleBinding that are not in appConfiguration: frontend.Server?

Also can you add the above examples to the examples of the repo to help others better understand.

Thank you!

How to add a resource that does not exist in konfig?

General Question

How do I add a resource that doesn't exist in konfig, such as middleware for traefik? Please help me with an example.

My base/base.k reads as follows.

import konfig.models.kube.frontend
import konfig.models.kube.frontend.service
import konfig.models.kube.frontend.container
import konfig.models.kube.frontend.container.port.container_port
import konfig.models.kube.frontend.serviceaccount as sa
import konfig.models.kube.frontend.rbac
import konfig.models.kube.utils

appPort: container_port.ContainerPort.containerPort = 8989
appOrg: str = "cnrancher"
appBuilder: utils.ApplicationBuilder = utils.ApplicationBuilder {}

rbac.ClusterRoleBinding {
    name = option("app")
    labels: appBuilder.labels
    metadata: {}
    subjects = [{
        kind = "ServiceAccount"
        name = option("app")
        namespace = option("app")
    }]
    roleRef = {
        apiGroup = "rbac.authorization.k8s.io"
        kind = "ClusterRole"
        name = "cluster-admin"
    }
}
# Application Configuration
appConfiguration: frontend.Server {
    # Main Container Configuration
    mainContainer = container.Main {
        ports = [{containerPort = appPort}]
        args = [
            "--https-listen-port=0"
            "--http-listen-port=" + str(appPort)
        ]
    }
    image = appOrg + "/" + option("app") + ":" + "latest"
    services = [service.Service {
        name = option("app")
        type = "ClusterIP"
        ports = [{
            port = appPort
            targetPort = appPort
        }]
        labels: appBuilder.labels
    }]
    serviceAccount = sa.ServiceAccount {
        name = option("app")
        labels: appBuilder.labels
    }
}

How should I write my dev/main.k, my current one looks like this, traefik doesn't generate it correctly, so I commented it out.

kcl mod add traefik
import konfig.models.kube.frontend
import konfig.models.kube.templates.resource as res_tpl
import konfig.models.kube.frontend.ingress
import traefik.v1alpha1.traefik_io_v1alpha1_middleware as mw


# appMW: mw.Middleware {
#     metadata = {
#         name = option("app")
#         namespace = option("app")
#         labels: appBuilder.labels
#     }
#     spec = {
#         basicAuth = {
#             secret = option("app")
#             removeHeader = True
#         }
#     }
# }

# Or?
# mw = {
#     apiVersion = "traefik.containo.us/v1alpha1"
#     kind = "Middleware"
#     metadata = {
#         name = option("app")
#         namespace = option("app")
#         labels = {app = option("app")}
#     }
#     spec = {
#         basicAuth = {
#             secret = option("app")
#             removeHeader = True
#         }
#     }
# }
appConfiguration: frontend.Server {
    schedulingStrategy.resource = res_tpl.tiny
    secrets = [{
        # name = option("app")
        data = {auth = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
    }]
    ingresses = [ingress.Ingress {
        name = option("app")
        labels: appBuilder.labels
        annotations = {
            "traefik.ingress.kubernetes.io/router.middlewares": "{}-{}@kubernetescrd".format(option("app"), option("app"))
            "traefik.ingress.kubernetes.io/router.entrypoints": "websecure"
        }
        rules = [{
            host = "example.com"
            http.paths = [{
                path = "/"
                pathType = "Prefix"
                backend.service: {
                    name = option("app")
                    port.number = appPort
                }
            }]
        }]
    }]
} 

Thks

provider = [*provider, *DatabaseBackend(config).provider]

Bug Report

我在windows 11 中运行nginx 示例出现以下错误。我刚学习且没有编程经验,不知道怎么处理

1. Minimal reproduce step (Required)

[ ~ ]# cd .\examples\appops\nginx-example\dev\

[ ~ ]# kcl.exe .\main.k
error[E2L23]: CompileError
  --> C:\user\xiaosi\konfig\models\kube\backend\server_backend.k:65:33
   |
65 |         provider = [*provider, *StorageBackend(config).provider]
   |                                 ^ name 'StorageBackend' is not defined, did you mean '["ServerBackend"]'?
   |


error[E2L23]: CompileError
  --> C:\user\xiaosi\konfig\models\kube\backend\server_backend.k:68:33
   |
68 |         provider = [*provider, *DatabaseBackend(config).provider]
   |                                 ^ name 'DatabaseBackend' is not defined
   |

2. What did you expect to see? (Required)

希望能够解决这个问题,能像教程那样正常输出

3. What did you see instead (Required)

kube\backend\server_backend.k:65:33   # name 'StorageBackend' is not defined,
models\kube\backend\server_backend.k:68:33   # name 'DatabaseBackend' is not defined

4. What is your KCL components version? (Required)

[ ~ ]# kcl.exe -v         
kcl version 0.8.0

Konfig nginx例子文档写的是啥啥啥啊?

Bug Report

完成编译,可以看到 3 个资源:

一个 name 为 nginx-exampledev 的 Deployment
一个 name 为 nginx-example 的 Namespace
一个 name 为 nginx-example 的 Service

但是,你给的例子结果是这个啊:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: sampleappprod
  namespace: sampleapp

我想请问一下:

  1. 一个 name 为 nginx-exampledev 的 Deployment 咋来的?
  2. 一个 name 为 nginx-example 的 Namespace 又是咋来的?

1. Minimal reproduce step (Required)

中文文档:https://www.kcl-lang.io/zh-CN/docs/user_docs/guides/working-with-konfig/guide#1-%E9%85%8D%E7%BD%AE%E7%BC%96%E8%AF%91

2. What did you expect to see? (Required)

正确的文档

3. What did you see instead (Required)

错误的,看不懂的文档

4. What is your KCL components version? (Required)

  • kcl: 0.9
  • konfig: 0.5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.