Kompose - 架構 - Kompose 繁體中文

架構與內部設計

kompose 有 3 個階段:載入程式轉換器輸出器。每個階段都應具有明確定義的介面,以便輕鬆撰寫並插入新的載入程式、轉換器或輸出器。目前僅定義載入程式和轉換器介面。

Design Diagram

載入程式

載入程式會讀取輸入檔案,現階段 kompose 支援 Compose v1、v2,並轉換成 KomposeObject。

載入程式由載入程式介面表示

type Loader interface {
      LoadFile(file string) kobject.KomposeObject
}

每個載入程式「實作」應放入 kompose/pkg/loader(如 compose)。未來將支援更多輸入格式。您可參閱以下網址取得更多詳細資訊:

KomposeObject

KomposeObject 是 Kompose 內部表示,說明從輸入檔案載入的所有容器。第一版的 KomposeObject 如下(來源:kobject.go

// KomposeObject holds the generic struct of Kompose transformation
type KomposeObject struct {
    ServiceConfigs map[string]ServiceConfig
}

// ServiceConfig holds the basic struct of a container
type ServiceConfig struct {
    ContainerName string
    Image         string
    Environment   []EnvVar
    Port          []Ports
    Command       []string
    WorkingDir    string
    Args          []string
    Volumes       []string
    Network       []string
    Labels        map[string]string
    Annotations   map[string]string
    CPUSet        string
    CPUShares     int64
    CPUQuota      int64
    CapAdd        []string
    CapDrop       []string
    Entrypoint    []string
    Expose        []string
    Privileged    bool
    Restart       string
    User          string
}

轉換器

轉換器會擷取 KomposeObject,並轉換成目標/輸出格式(目前有 Kubernetes/OpenShift 物件組)。類似於 Loader,轉換器會由轉換器介面表示

type Transformer interface {
     Transform(kobject.KomposeObject, kobject.ConvertOptions) []runtime.Object
}

如果您想要新增含有不同類型的物件的提供者,則可以尋找轉換器。目前,Kompose 支援 Kubernetes(預設)和 OpenShift 提供者。有關更多詳細資訊,請參閱:

輸出器

輸出器會擷取轉換器結果並執行指定的動作。例如,動作可以將結果顯示到 stdout 或直接將人工製品部署到 Kubernetes/OpenShift。