From 5ca1c8269c4d2f98cd203182a667e4d295871200 Mon Sep 17 00:00:00 2001 From: Dayuan Date: Tue, 14 May 2024 10:22:03 +0800 Subject: [PATCH] feat: move internal.kusion.io to api.kusion.io (#1119) --- .../v1/marshal.go | 0 .../v1/marshal_test.go | 0 pkg/apis/api.kusion.io/v1/types.go | 464 +++++++++++++++++ .../v1/unmarshal.go | 0 .../v1/unmarshal_test.go | 0 pkg/apis/internal.kusion.io/group.go | 3 - pkg/apis/internal.kusion.io/v1/types.go | 468 ------------------ pkg/backend/backend.go | 2 +- pkg/backend/backend_test.go | 2 +- pkg/backend/storages/completion.go | 2 +- pkg/backend/storages/completion_test.go | 2 +- pkg/backend/storages/local.go | 2 +- pkg/backend/storages/local_test.go | 2 +- pkg/backend/storages/oss.go | 2 +- pkg/backend/storages/oss_test.go | 2 +- pkg/backend/storages/s3.go | 2 +- pkg/backend/storages/s3_test.go | 2 +- pkg/backend/storages/validation.go | 2 +- pkg/backend/storages/validation_test.go | 2 +- pkg/cmd/apply/apply_test.go | 3 +- pkg/cmd/config/list/cmd_test.go | 2 +- pkg/cmd/destroy/destroy_test.go | 3 +- pkg/cmd/preview/preview_test.go | 3 +- pkg/config/operator.go | 2 +- pkg/config/operator_test.go | 2 +- pkg/config/registry.go | 2 +- pkg/config/util.go | 2 +- pkg/config/util_test.go | 2 +- pkg/config/validation.go | 2 +- pkg/config/validation_test.go | 2 +- pkg/domain/entity/backend.go | 2 +- pkg/domain/request/backend_request.go | 2 +- pkg/engine/api/builders/appconfig_builder.go | 5 +- .../api/builders/appconfig_builder_test.go | 17 +- .../api/generate/generator/generator.go | 3 +- pkg/infra/persistence/backend_model.go | 2 +- pkg/infra/persistence/backend_test.go | 3 +- .../app_configurations_generator.go | 17 +- .../app_configurations_generator_test.go | 21 +- .../generators/workload/job_generator.go | 5 +- .../generators/workload/job_generator_test.go | 21 +- .../workload/secret/secret_generator.go | 21 +- .../workload/secret/secret_generator_test.go | 13 +- .../generators/workload/service_generator.go | 33 +- .../workload/service_generator_test.go | 63 ++- .../generators/workload/workload_generator.go | 33 +- .../workload/workload_generator_test.go | 153 +++--- pkg/server/manager/stack/util.go | 9 +- 48 files changed, 694 insertions(+), 713 deletions(-) rename pkg/apis/{internal.kusion.io => api.kusion.io}/v1/marshal.go (100%) rename pkg/apis/{internal.kusion.io => api.kusion.io}/v1/marshal_test.go (100%) rename pkg/apis/{internal.kusion.io => api.kusion.io}/v1/unmarshal.go (100%) rename pkg/apis/{internal.kusion.io => api.kusion.io}/v1/unmarshal_test.go (100%) delete mode 100644 pkg/apis/internal.kusion.io/group.go delete mode 100644 pkg/apis/internal.kusion.io/v1/types.go diff --git a/pkg/apis/internal.kusion.io/v1/marshal.go b/pkg/apis/api.kusion.io/v1/marshal.go similarity index 100% rename from pkg/apis/internal.kusion.io/v1/marshal.go rename to pkg/apis/api.kusion.io/v1/marshal.go diff --git a/pkg/apis/internal.kusion.io/v1/marshal_test.go b/pkg/apis/api.kusion.io/v1/marshal_test.go similarity index 100% rename from pkg/apis/internal.kusion.io/v1/marshal_test.go rename to pkg/apis/api.kusion.io/v1/marshal_test.go diff --git a/pkg/apis/api.kusion.io/v1/types.go b/pkg/apis/api.kusion.io/v1/types.go index 575812c2..2228b141 100644 --- a/pkg/apis/api.kusion.io/v1/types.go +++ b/pkg/apis/api.kusion.io/v1/types.go @@ -17,6 +17,9 @@ package v1 import ( "time" + "gopkg.in/yaml.v2" + v1 "k8s.io/api/core/v1" + "kusionstack.io/kusion/pkg/version" ) @@ -95,6 +98,467 @@ type Workspace struct { Context GenericConfig `yaml:"context,omitempty" json:"context,omitempty"` } +const ( + BuiltinModulePrefix = "" + ProbePrefix = "service.container.probe." + TypeHTTP = BuiltinModulePrefix + ProbePrefix + "Http" + TypeExec = BuiltinModulePrefix + ProbePrefix + "Exec" + TypeTCP = BuiltinModulePrefix + ProbePrefix + "Tcp" +) + +// Container describes how the App's tasks are expected to be run. +type Container struct { + // Image to run for this container + Image string `yaml:"image" json:"image"` + // Entrypoint array. + // The image's ENTRYPOINT is used if this is not provided. + Command []string `yaml:"command,omitempty" json:"command,omitempty"` + // Arguments to the entrypoint. + // The image's CMD is used if this is not provided. + Args []string `yaml:"args,omitempty" json:"args,omitempty"` + // Collection of environment variables to set in the container. + // The value of environment variable may be static text or a value from a secret. + Env yaml.MapSlice `yaml:"env,omitempty" json:"env,omitempty"` + // The current working directory of the running process defined in entrypoint. + WorkingDir string `yaml:"workingDir,omitempty" json:"workingDir,omitempty"` + // Resource requirements for this container. + Resources map[string]string `yaml:"resources,omitempty" json:"resources,omitempty"` + // Files configures one or more files to be created in the container. + Files map[string]FileSpec `yaml:"files,omitempty" json:"files,omitempty"` + // Dirs configures one or more volumes to be mounted to the specified folder. + Dirs map[string]string `yaml:"dirs,omitempty" json:"dirs,omitempty"` + // Periodic probe of container liveness. + LivenessProbe *Probe `yaml:"livenessProbe,omitempty" json:"livenessProbe,omitempty"` + // Periodic probe of container service readiness. + ReadinessProbe *Probe `yaml:"readinessProbe,omitempty" json:"readinessProbe,omitempty"` + // StartupProbe indicates that the Pod has successfully initialized. + StartupProbe *Probe `yaml:"startupProbe,omitempty" json:"startupProbe,omitempty"` + // Actions that the management system should take in response to container lifecycle events. + Lifecycle *Lifecycle `yaml:"lifecycle,omitempty" json:"lifecycle,omitempty"` +} + +// FileSpec defines the target file in a Container +type FileSpec struct { + // The content of target file in plain text. + Content string `yaml:"content,omitempty" json:"content,omitempty"` + // Source for the file content, might be a reference to a secret value. + ContentFrom string `yaml:"contentFrom,omitempty" json:"contentFrom,omitempty"` + // Mode bits used to set permissions on this file. + Mode string `yaml:"mode" json:"mode"` +} + +// TypeWrapper is a thin wrapper to make YAML decoder happy. +type TypeWrapper struct { + // Type of action to be taken. + Type string `yaml:"_type" json:"_type"` +} + +// Probe describes a health check to be performed against a container to determine whether it is +// alive or ready to receive traffic. +type Probe struct { + // The action taken to determine the health of a container. + ProbeHandler *ProbeHandler `yaml:"probeHandler" json:"probeHandler"` + // Number of seconds after the container has started before liveness probes are initiated. + InitialDelaySeconds int32 `yaml:"initialDelaySeconds,omitempty" json:"initialDelaySeconds,omitempty"` + // Number of seconds after which the probe times out. + TimeoutSeconds int32 `yaml:"timeoutSeconds,omitempty" json:"timeoutSeconds,omitempty"` + // How often (in seconds) to perform the probe. + PeriodSeconds int32 `yaml:"periodSeconds,omitempty" json:"periodSeconds,omitempty"` + // Minimum consecutive successes for the probe to be considered successful after having failed. + SuccessThreshold int32 `yaml:"successThreshold,omitempty" json:"successThreshold,omitempty"` + // Minimum consecutive failures for the probe to be considered failed after having succeeded. + FailureThreshold int32 `yaml:"failureThreshold,omitempty" json:"failureThreshold,omitempty"` +} + +// ProbeHandler defines a specific action that should be taken in a probe. +// One and only one of the fields must be specified. +type ProbeHandler struct { + // Type of action to be taken. + TypeWrapper `yaml:"_type" json:"_type"` + // Exec specifies the action to take. + // +optional + *ExecAction `yaml:",inline" json:",inline"` + // HTTPGet specifies the http request to perform. + // +optional + *HTTPGetAction `yaml:",inline" json:",inline"` + // TCPSocket specifies an action involving a TCP port. + // +optional + *TCPSocketAction `yaml:",inline" json:",inline"` +} + +// ExecAction describes a "run in container" action. +type ExecAction struct { + // Command is the command line to execute inside the container, the working directory for the + // command is root ('/') in the container's filesystem. + // Exit status of 0 is treated as live/healthy and non-zero is unhealthy. + Command []string `yaml:"command,omitempty" json:"command,omitempty"` +} + +// HTTPGetAction describes an action based on HTTP Get requests. +type HTTPGetAction struct { + // URL is the full qualified url location to send HTTP requests. + URL string `yaml:"url,omitempty" json:"url,omitempty"` + // Custom headers to set in the request. HTTP allows repeated headers. + Headers map[string]string `yaml:"headers,omitempty" json:"headers,omitempty"` +} + +// TCPSocketAction describes an action based on opening a socket. +type TCPSocketAction struct { + // URL is the full qualified url location to open a socket. + URL string `yaml:"url,omitempty" json:"url,omitempty"` +} + +// Lifecycle describes actions that the management system should take in response +// to container lifecycle events. +type Lifecycle struct { + // PreStop is called immediately before a container is terminated due to an + // API request or management event such as liveness/startup probe failure, + // preemption, resource contention, etc. + PreStop *LifecycleHandler `yaml:"preStop,omitempty" json:"preStop,omitempty"` + // PostStart is called immediately after a container is created. + PostStart *LifecycleHandler `yaml:"postStart,omitempty" json:"postStart,omitempty"` +} + +// LifecycleHandler defines a specific action that should be taken in a lifecycle +// hook. One and only one of the fields, except TCPSocket must be specified. +type LifecycleHandler struct { + // Type of action to be taken. + TypeWrapper `yaml:"_type" json:"_type"` + // Exec specifies the action to take. + // +optional + *ExecAction `yaml:",inline" json:",inline"` + // HTTPGet specifies the http request to perform. + // +optional + *HTTPGetAction `yaml:",inline" json:",inline"` +} + +type Protocol string + +const ( + TCP Protocol = "TCP" + UDP Protocol = "UDP" +) + +// Port defines the exposed port of Service. +type Port struct { + // Port is the exposed port of the Service. + Port int `yaml:"port,omitempty" json:"port,omitempty"` + // TargetPort is the backend .Container port. + TargetPort int `yaml:"targetPort,omitempty" json:"targetPort,omitempty"` + // Protocol is protocol used to expose the port, support ProtocolTCP and ProtocolUDP. + Protocol Protocol `yaml:"protocol,omitempty" json:"protocol,omitempty"` +} + +type Secret struct { + Type string `yaml:"type" json:"type"` + Params map[string]string `yaml:"params,omitempty" json:"params,omitempty"` + Data map[string]string `yaml:"data,omitempty" json:"data,omitempty"` + Immutable bool `yaml:"immutable,omitempty" json:"immutable,omitempty"` +} + +const ( + FieldLabels = "labels" + FieldAnnotations = "annotations" + FieldReplicas = "replicas" +) + +// Base defines set of attributes shared by different workload profile, e.g. Service and Job. +type Base struct { + // The templates of containers to be run. + Containers map[string]Container `yaml:"containers,omitempty" json:"containers,omitempty"` + // The number of containers that should be run. + Replicas *int32 `yaml:"replicas,omitempty" json:"replicas,omitempty"` + // Secret + Secrets map[string]Secret `json:"secrets,omitempty" yaml:"secrets,omitempty"` + // Dirs configures one or more volumes to be mounted to the specified folder. + Dirs map[string]string `json:"dirs,omitempty" yaml:"dirs,omitempty"` + // Labels and Annotations can be used to attach arbitrary metadata as key-value pairs to resources. + Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"` + Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"` +} + +type ServiceType string + +const ( + ModuleService = "service" + ModuleServiceType = "type" + Deployment ServiceType = "Deployment" + Collaset ServiceType = "CollaSet" +) + +// Service is a kind of workload profile that describes how to run your application code. +// This is typically used for long-running web applications that should "never" go down, and handle short-lived latency-sensitive +// web requests, or events. +type Service struct { + Base `yaml:",inline" json:",inline"` + // Type represents the type of workload.Service, support Deployment and CollaSet. + Type ServiceType `yaml:"type" json:"type"` + // Ports describe the list of ports need getting exposed. + Ports []Port `yaml:"ports,omitempty" json:"ports,omitempty"` +} + +const ModuleJob = "job" + +// Job is a kind of workload profile that describes how to run your application code. This is typically used for tasks that take from +// a few seconds to a few days to complete. +type Job struct { + Base `yaml:",inline" json:",inline"` + // The scheduling strategy in Cron format: https://en.wikipedia.org/wiki/Cron. + Schedule string `yaml:"schedule,omitempty" json:"schedule,omitempty"` +} + +const ( + TypeJob = "job.Job" + TypeService = "service.Service" +) + +type Header struct { + Type string `yaml:"_type" json:"_type"` +} + +type Workload struct { + Header `yaml:",inline" json:",inline"` + *Service `yaml:",inline" json:",inline"` + *Job `yaml:",inline" json:",inline"` +} + +type Accessory map[string]interface{} + +// AppConfiguration is a developer-centric definition that describes how to run an App. The application model is built on a decade +// of experience from AntGroup in operating a large-scale internal developer platform and combines the best ideas and practices from the +// community. +// +// Note: AppConfiguration per se is not a Kusion Module +// +// Example: +// import models.schema.v1 as ac +// import models.schema.v1.workload as wl +// import models.schema.v1.workload.container as c +// import models.schema.v1.workload.container.probe as p +// import models.schema.v1.monitoring as m +// import models.schema.v1.database as d +// +// helloWorld: ac.AppConfiguration { +// # Built-in module +// workload: wl.Service { +// containers: { +// "main": c.Container { +// image: "ghcr.io/kusion-stack/samples/helloworld:latest" +// # Configure a HTTP readiness probe +// readinessProbe: p.Probe { +// probeHandler: p.Http { +// url: "http://localhost:80" +// } +// } +// } +// } +// } +// +// # extend accessories module base +// accessories: { +// # Built-in module, key represents the module source +// "kusionstack/mysql@v0.1" : d.MySQL { +// type: "cloud" +// version: "8.0" +// } +// # Built-in module, key represents the module source +// "kusionstack/prometheus@v0.1" : m.Prometheus { +// path: "/metrics" +// } +// # Customized module, key represents the module source +// "foo/customize": customizedModule { +// ... +// } +// } +// +// # extend pipeline module base +// pipeline: { +// # Step is a module +// "step" : Step { +// use: "exec" +// args: ["--test-all"] +// } +// } +// +// # Dependent app list +// dependency: { +// dependentApps: ["init-kusion"] +// } +// } +type AppConfiguration struct { + // Name of the target App. + Name string `json:"name,omitempty" yaml:"name,omitempty"` + // Workload defines how to run your application code. + Workload *Workload `json:"workload" yaml:"workload"` + // Accessories defines a collection of accessories that will be attached to the workload. + // The key in this map represents the module source. e.g. kusionstack/mysql@v0.1 + Accessories map[string]Accessory `json:"accessories,omitempty" yaml:"accessories,omitempty"` + // Labels and Annotations can be used to attach arbitrary metadata as key-value pairs to resources. + Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"` + Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"` +} + +// Patcher contains fields should be patched into the workload corresponding fields +type Patcher struct { + // Environments represent the environment variables patched to all containers in the workload. + Environments []v1.EnvVar `json:"environments" yaml:"environments"` + // Labels represent the labels patched to both the workload and pod. + Labels map[string]string `json:"labels" yaml:"labels"` + // Annotations represent the annotations patched to both the workload and pod. + Annotations map[string]string `json:"annotations" yaml:"annotations"` +} + +const ConfigBackends = "backends" + +// Config contains configurations for kusion cli, which stores in ${KUSION_HOME}/config.yaml. +type Config struct { + // Backends contains the configurations for multiple backends. + Backends *BackendConfigs `yaml:"backends,omitempty" json:"backends,omitempty"` +} + +const ( + DefaultBackendName = "default" + + BackendCurrent = "current" + BackendType = "type" + BackendConfigItems = "configs" + BackendLocalPath = "path" + BackendGenericOssEndpoint = "endpoint" + BackendGenericOssAK = "accessKeyID" + BackendGenericOssSK = "accessKeySecret" + BackendGenericOssBucket = "bucket" + BackendGenericOssPrefix = "prefix" + BackendS3Region = "region" + + BackendTypeLocal = "local" + BackendTypeOss = "oss" + BackendTypeS3 = "s3" + + EnvOssAccessKeyID = "OSS_ACCESS_KEY_ID" + EnvOssAccessKeySecret = "OSS_ACCESS_KEY_SECRET" + EnvAwsAccessKeyID = "AWS_ACCESS_KEY_ID" + EnvAwsSecretAccessKey = "AWS_SECRET_ACCESS_KEY" + EnvAwsDefaultRegion = "AWS_DEFAULT_REGION" + EnvAwsRegion = "AWS_REGION" +) + +// BackendConfigs contains the configuration of multiple backends and the current backend. +type BackendConfigs struct { + // Current is the name of the current used backend. + Current string `yaml:"current,omitempty" json:"current,omitempty"` + + // Backends contains the types and configs of multiple backends, whose key is the backend name. + Backends map[string]*BackendConfig `yaml:",omitempty,inline" json:",omitempty,inline"` +} + +// BackendConfig contains the type and configs of a backend, which is used to store Spec, State and Workspace. +type BackendConfig struct { + // Type is the backend type, supports BackendTypeLocal, BackendTypeOss, BackendTypeS3. + Type string `yaml:"type,omitempty" json:"type,omitempty"` + + // Configs contains config items of the backend, whose keys differ from different backend types. + Configs map[string]any `yaml:"configs,omitempty" json:"configs,omitempty"` +} + +// BackendLocalConfig contains the config of using local file system as backend, which can be converted +// from BackendConfig if Type is BackendTypeLocal. +type BackendLocalConfig struct { + // Path of the directory to store the files. + Path string `yaml:"path,omitempty" json:"path,omitempty"` +} + +// BackendOssConfig contains the config of using OSS as backend, which can be converted from BackendConfig +// if Type is BackendOssConfig. +type BackendOssConfig struct { + *GenericBackendObjectStorageConfig `yaml:",inline" json:",inline"` // OSS asks for non-empty endpoint +} + +// BackendS3Config contains the config of using S3 as backend, which can be converted from BackendConfig +// if Type is BackendS3Config. +type BackendS3Config struct { + *GenericBackendObjectStorageConfig `yaml:",inline" json:",inline"` + + // Region of S3. + Region string `yaml:"region,omitempty" json:"region,omitempty"` +} + +// GenericBackendObjectStorageConfig contains generic configs which can be reused by BackendOssConfig and +// BackendS3Config. +type GenericBackendObjectStorageConfig struct { + // Endpoint of the object storage service. + Endpoint string `yaml:"endpoint,omitempty" json:"endpoint,omitempty"` + + // AccessKeyID of the object storage service. + AccessKeyID string `yaml:"accessKeyID,omitempty" json:"accessKeyID,omitempty"` + + // AccessKeySecret of the object storage service. + AccessKeySecret string `yaml:"accessKeySecret,omitempty" json:"accessKeySecret,omitempty"` + + // Bucket of the object storage service. + Bucket string `yaml:"bucket" json:"bucket"` + + // Prefix of the key to store the files. + Prefix string `yaml:"prefix,omitempty" json:"prefix,omitempty"` +} + +// ToLocalBackend converts BackendConfig to structured BackendLocalConfig, works only when the Type +// is BackendTypeLocal, and the Configs are with correct type, or return nil. +func (b *BackendConfig) ToLocalBackend() *BackendLocalConfig { + if b.Type != BackendTypeLocal { + return nil + } + path, _ := b.Configs[BackendLocalPath].(string) + return &BackendLocalConfig{ + Path: path, + } +} + +// ToOssBackend converts BackendConfig to structured BackendOssConfig, works only when the Type is +// BackendTypeOss, and the Configs are with correct type, or return nil. +func (b *BackendConfig) ToOssBackend() *BackendOssConfig { + if b.Type != BackendTypeOss { + return nil + } + endpoint, _ := b.Configs[BackendGenericOssEndpoint].(string) + accessKeyID, _ := b.Configs[BackendGenericOssAK].(string) + accessKeySecret, _ := b.Configs[BackendGenericOssSK].(string) + bucket, _ := b.Configs[BackendGenericOssBucket].(string) + prefix, _ := b.Configs[BackendGenericOssPrefix].(string) + return &BackendOssConfig{ + &GenericBackendObjectStorageConfig{ + Endpoint: endpoint, + AccessKeyID: accessKeyID, + AccessKeySecret: accessKeySecret, + Bucket: bucket, + Prefix: prefix, + }, + } +} + +// ToS3Backend converts BackendConfig to structured BackendS3Config, works only when the Type is +// BackendTypeS3, and the Configs are with correct type, or return nil. +func (b *BackendConfig) ToS3Backend() *BackendS3Config { + if b.Type != BackendTypeS3 { + return nil + } + endpoint, _ := b.Configs[BackendGenericOssEndpoint].(string) + accessKeyID, _ := b.Configs[BackendGenericOssAK].(string) + accessKeySecret, _ := b.Configs[BackendGenericOssSK].(string) + bucket, _ := b.Configs[BackendGenericOssBucket].(string) + prefix, _ := b.Configs[BackendGenericOssPrefix].(string) + region, _ := b.Configs[BackendS3Region].(string) + return &BackendS3Config{ + GenericBackendObjectStorageConfig: &GenericBackendObjectStorageConfig{ + Endpoint: endpoint, + AccessKeyID: accessKeyID, + AccessKeySecret: accessKeySecret, + Bucket: bucket, + Prefix: prefix, + }, + Region: region, + } +} + // ModuleConfigs is a set of multiple ModuleConfig, whose key is the module name. type ModuleConfigs map[string]*ModuleConfig diff --git a/pkg/apis/internal.kusion.io/v1/unmarshal.go b/pkg/apis/api.kusion.io/v1/unmarshal.go similarity index 100% rename from pkg/apis/internal.kusion.io/v1/unmarshal.go rename to pkg/apis/api.kusion.io/v1/unmarshal.go diff --git a/pkg/apis/internal.kusion.io/v1/unmarshal_test.go b/pkg/apis/api.kusion.io/v1/unmarshal_test.go similarity index 100% rename from pkg/apis/internal.kusion.io/v1/unmarshal_test.go rename to pkg/apis/api.kusion.io/v1/unmarshal_test.go diff --git a/pkg/apis/internal.kusion.io/group.go b/pkg/apis/internal.kusion.io/group.go deleted file mode 100644 index 0864596c..00000000 --- a/pkg/apis/internal.kusion.io/group.go +++ /dev/null @@ -1,3 +0,0 @@ -package internalkusionio - -const Group = "internal.kusion.io" diff --git a/pkg/apis/internal.kusion.io/v1/types.go b/pkg/apis/internal.kusion.io/v1/types.go deleted file mode 100644 index af4cc6ec..00000000 --- a/pkg/apis/internal.kusion.io/v1/types.go +++ /dev/null @@ -1,468 +0,0 @@ -package v1 - -import ( - "gopkg.in/yaml.v2" - v1 "k8s.io/api/core/v1" -) - -const ( - ProbePrefix = "service.container.probe." - TypeHTTP = ProbePrefix + "Http" - TypeExec = ProbePrefix + "Exec" - TypeTCP = ProbePrefix + "Tcp" -) - -// Container describes how the App's tasks are expected to be run. -type Container struct { - // Image to run for this container - Image string `yaml:"image" json:"image"` - // Entrypoint array. - // The image's ENTRYPOINT is used if this is not provided. - Command []string `yaml:"command,omitempty" json:"command,omitempty"` - // Arguments to the entrypoint. - // The image's CMD is used if this is not provided. - Args []string `yaml:"args,omitempty" json:"args,omitempty"` - // Collection of environment variables to set in the container. - // The value of environment variable may be static text or a value from a secret. - Env yaml.MapSlice `yaml:"env,omitempty" json:"env,omitempty"` - // The current working directory of the running process defined in entrypoint. - WorkingDir string `yaml:"workingDir,omitempty" json:"workingDir,omitempty"` - // Resource requirements for this container. - Resources map[string]string `yaml:"resources,omitempty" json:"resources,omitempty"` - // Files configures one or more files to be created in the container. - Files map[string]FileSpec `yaml:"files,omitempty" json:"files,omitempty"` - // Dirs configures one or more volumes to be mounted to the specified folder. - Dirs map[string]string `yaml:"dirs,omitempty" json:"dirs,omitempty"` - // Periodic probe of container liveness. - LivenessProbe *Probe `yaml:"livenessProbe,omitempty" json:"livenessProbe,omitempty"` - // Periodic probe of container service readiness. - ReadinessProbe *Probe `yaml:"readinessProbe,omitempty" json:"readinessProbe,omitempty"` - // StartupProbe indicates that the Pod has successfully initialized. - StartupProbe *Probe `yaml:"startupProbe,omitempty" json:"startupProbe,omitempty"` - // Actions that the management system should take in response to container lifecycle events. - Lifecycle *Lifecycle `yaml:"lifecycle,omitempty" json:"lifecycle,omitempty"` -} - -// FileSpec defines the target file in a Container -type FileSpec struct { - // The content of target file in plain text. - Content string `yaml:"content,omitempty" json:"content,omitempty"` - // Source for the file content, might be a reference to a secret value. - ContentFrom string `yaml:"contentFrom,omitempty" json:"contentFrom,omitempty"` - // Mode bits used to set permissions on this file. - Mode string `yaml:"mode" json:"mode"` -} - -// TypeWrapper is a thin wrapper to make YAML decoder happy. -type TypeWrapper struct { - // Type of action to be taken. - Type string `yaml:"_type" json:"_type"` -} - -// Probe describes a health check to be performed against a container to determine whether it is -// alive or ready to receive traffic. -type Probe struct { - // The action taken to determine the health of a container. - ProbeHandler *ProbeHandler `yaml:"probeHandler" json:"probeHandler"` - // Number of seconds after the container has started before liveness probes are initiated. - InitialDelaySeconds int32 `yaml:"initialDelaySeconds,omitempty" json:"initialDelaySeconds,omitempty"` - // Number of seconds after which the probe times out. - TimeoutSeconds int32 `yaml:"timeoutSeconds,omitempty" json:"timeoutSeconds,omitempty"` - // How often (in seconds) to perform the probe. - PeriodSeconds int32 `yaml:"periodSeconds,omitempty" json:"periodSeconds,omitempty"` - // Minimum consecutive successes for the probe to be considered successful after having failed. - SuccessThreshold int32 `yaml:"successThreshold,omitempty" json:"successThreshold,omitempty"` - // Minimum consecutive failures for the probe to be considered failed after having succeeded. - FailureThreshold int32 `yaml:"failureThreshold,omitempty" json:"failureThreshold,omitempty"` -} - -// ProbeHandler defines a specific action that should be taken in a probe. -// One and only one of the fields must be specified. -type ProbeHandler struct { - // Type of action to be taken. - TypeWrapper `yaml:"_type" json:"_type"` - // Exec specifies the action to take. - // +optional - *ExecAction `yaml:",inline" json:",inline"` - // HTTPGet specifies the http request to perform. - // +optional - *HTTPGetAction `yaml:",inline" json:",inline"` - // TCPSocket specifies an action involving a TCP port. - // +optional - *TCPSocketAction `yaml:",inline" json:",inline"` -} - -// ExecAction describes a "run in container" action. -type ExecAction struct { - // Command is the command line to execute inside the container, the working directory for the - // command is root ('/') in the container's filesystem. - // Exit status of 0 is treated as live/healthy and non-zero is unhealthy. - Command []string `yaml:"command,omitempty" json:"command,omitempty"` -} - -// HTTPGetAction describes an action based on HTTP Get requests. -type HTTPGetAction struct { - // URL is the full qualified url location to send HTTP requests. - URL string `yaml:"url,omitempty" json:"url,omitempty"` - // Custom headers to set in the request. HTTP allows repeated headers. - Headers map[string]string `yaml:"headers,omitempty" json:"headers,omitempty"` -} - -// TCPSocketAction describes an action based on opening a socket. -type TCPSocketAction struct { - // URL is the full qualified url location to open a socket. - URL string `yaml:"url,omitempty" json:"url,omitempty"` -} - -// Lifecycle describes actions that the management system should take in response -// to container lifecycle events. -type Lifecycle struct { - // PreStop is called immediately before a container is terminated due to an - // API request or management event such as liveness/startup probe failure, - // preemption, resource contention, etc. - PreStop *LifecycleHandler `yaml:"preStop,omitempty" json:"preStop,omitempty"` - // PostStart is called immediately after a container is created. - PostStart *LifecycleHandler `yaml:"postStart,omitempty" json:"postStart,omitempty"` -} - -// LifecycleHandler defines a specific action that should be taken in a lifecycle -// hook. One and only one of the fields, except TCPSocket must be specified. -type LifecycleHandler struct { - // Type of action to be taken. - TypeWrapper `yaml:"_type" json:"_type"` - // Exec specifies the action to take. - // +optional - *ExecAction `yaml:",inline" json:",inline"` - // HTTPGet specifies the http request to perform. - // +optional - *HTTPGetAction `yaml:",inline" json:",inline"` -} - -type Protocol string - -const ( - TCP Protocol = "TCP" - UDP Protocol = "UDP" -) - -// Port defines the exposed port of Service. -type Port struct { - // Port is the exposed port of the Service. - Port int `yaml:"port,omitempty" json:"port,omitempty"` - // TargetPort is the backend .Container port. - TargetPort int `yaml:"targetPort,omitempty" json:"targetPort,omitempty"` - // Protocol is protocol used to expose the port, support ProtocolTCP and ProtocolUDP. - Protocol Protocol `yaml:"protocol,omitempty" json:"protocol,omitempty"` -} - -type Secret struct { - Type string `yaml:"type" json:"type"` - Params map[string]string `yaml:"params,omitempty" json:"params,omitempty"` - Data map[string]string `yaml:"data,omitempty" json:"data,omitempty"` - Immutable bool `yaml:"immutable,omitempty" json:"immutable,omitempty"` -} - -const ( - FieldLabels = "labels" - FieldAnnotations = "annotations" - FieldReplicas = "replicas" -) - -// Base defines set of attributes shared by different workload profile, e.g. Service and Job. -type Base struct { - // The templates of containers to be run. - Containers map[string]Container `yaml:"containers,omitempty" json:"containers,omitempty"` - // The number of containers that should be run. - Replicas *int32 `yaml:"replicas,omitempty" json:"replicas,omitempty"` - // Secret - Secrets map[string]Secret `json:"secrets,omitempty" yaml:"secrets,omitempty"` - // Dirs configures one or more volumes to be mounted to the specified folder. - Dirs map[string]string `json:"dirs,omitempty" yaml:"dirs,omitempty"` - // Labels and Annotations can be used to attach arbitrary metadata as key-value pairs to resources. - Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"` - Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"` -} - -type ServiceType string - -const ( - ModuleService = "service" - ModuleServiceType = "type" - Deployment ServiceType = "Deployment" - Collaset ServiceType = "CollaSet" -) - -// Service is a kind of workload profile that describes how to run your application code. -// This is typically used for long-running web applications that should "never" go down, and handle short-lived latency-sensitive -// web requests, or events. -type Service struct { - Base `yaml:",inline" json:",inline"` - // Type represents the type of workload.Service, support Deployment and CollaSet. - Type ServiceType `yaml:"type" json:"type"` - // Ports describe the list of ports need getting exposed. - Ports []Port `yaml:"ports,omitempty" json:"ports,omitempty"` -} - -const ModuleJob = "job" - -// Job is a kind of workload profile that describes how to run your application code. This is typically used for tasks that take from -// a few seconds to a few days to complete. -type Job struct { - Base `yaml:",inline" json:",inline"` - // The scheduling strategy in Cron format: https://en.wikipedia.org/wiki/Cron. - Schedule string `yaml:"schedule,omitempty" json:"schedule,omitempty"` -} - -type Type string - -const ( - TypeJob = "job.Job" - TypeService = "service.Service" -) - -type Header struct { - Type string `yaml:"_type" json:"_type"` -} - -type Workload struct { - Header `yaml:",inline" json:",inline"` - *Service `yaml:",inline" json:",inline"` - *Job `yaml:",inline" json:",inline"` -} - -type Accessory map[string]interface{} - -// AppConfiguration is a developer-centric definition that describes how to run an App. The application model is built on a decade -// of experience from AntGroup in operating a large-scale internal developer platform and combines the best ideas and practices from the -// community. -// -// Note: AppConfiguration per se is not a Kusion Module -// -// Example: -// import models.schema.v1 as ac -// import models.schema.v1.workload as wl -// import models.schema.v1.workload.container as c -// import models.schema.v1.workload.container.probe as p -// import models.schema.v1.monitoring as m -// import models.schema.v1.database as d -// -// helloWorld: ac.AppConfiguration { -// # Built-in module -// workload: wl.Service { -// containers: { -// "main": c.Container { -// image: "ghcr.io/kusion-stack/samples/helloworld:latest" -// # Configure a HTTP readiness probe -// readinessProbe: p.Probe { -// probeHandler: p.Http { -// url: "http://localhost:80" -// } -// } -// } -// } -// } -// -// # extend accessories module base -// accessories: { -// # Built-in module, key represents the module source -// "kusionstack/mysql@v0.1" : d.MySQL { -// type: "cloud" -// version: "8.0" -// } -// # Built-in module, key represents the module source -// "kusionstack/prometheus@v0.1" : m.Prometheus { -// path: "/metrics" -// } -// # Customized module, key represents the module source -// "foo/customize": customizedModule { -// ... -// } -// } -// -// # extend pipeline module base -// pipeline: { -// # Step is a module -// "step" : Step { -// use: "exec" -// args: ["--test-all"] -// } -// } -// -// # Dependent app list -// dependency: { -// dependentApps: ["init-kusion"] -// } -// } -type AppConfiguration struct { - // Name of the target App. - Name string `json:"name,omitempty" yaml:"name,omitempty"` - // Workload defines how to run your application code. - Workload *Workload `json:"workload" yaml:"workload"` - // Accessories defines a collection of accessories that will be attached to the workload. - // The key in this map represents the module source. e.g. kusionstack/mysql@v0.1 - Accessories map[string]Accessory `json:"accessories,omitempty" yaml:"accessories,omitempty"` - // Labels and Annotations can be used to attach arbitrary metadata as key-value pairs to resources. - Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"` - Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"` -} - -// Patcher contains fields should be patched into the workload corresponding fields -type Patcher struct { - // Environments represent the environment variables patched to all containers in the workload. - Environments []v1.EnvVar `json:"environments" yaml:"environments"` - // Labels represent the labels patched to both the workload and pod. - Labels map[string]string `json:"labels" yaml:"labels"` - // Annotations represent the annotations patched to both the workload and pod. - Annotations map[string]string `json:"annotations" yaml:"annotations"` -} - -const ConfigBackends = "backends" - -// Config contains configurations for kusion cli, which stores in ${KUSION_HOME}/config.yaml. -type Config struct { - // Backends contains the configurations for multiple backends. - Backends *BackendConfigs `yaml:"backends,omitempty" json:"backends,omitempty"` -} - -const ( - DefaultBackendName = "default" - - BackendCurrent = "current" - BackendType = "type" - BackendConfigItems = "configs" - BackendLocalPath = "path" - BackendGenericOssEndpoint = "endpoint" - BackendGenericOssAK = "accessKeyID" - BackendGenericOssSK = "accessKeySecret" - BackendGenericOssBucket = "bucket" - BackendGenericOssPrefix = "prefix" - BackendS3Region = "region" - - BackendTypeLocal = "local" - BackendTypeOss = "oss" - BackendTypeS3 = "s3" - - EnvOssAccessKeyID = "OSS_ACCESS_KEY_ID" - EnvOssAccessKeySecret = "OSS_ACCESS_KEY_SECRET" - EnvAwsAccessKeyID = "AWS_ACCESS_KEY_ID" - EnvAwsSecretAccessKey = "AWS_SECRET_ACCESS_KEY" - EnvAwsDefaultRegion = "AWS_DEFAULT_REGION" - EnvAwsRegion = "AWS_REGION" -) - -// BackendConfigs contains the configuration of multiple backends and the current backend. -type BackendConfigs struct { - // Current is the name of the current used backend. - Current string `yaml:"current,omitempty" json:"current,omitempty"` - - // Backends contains the types and configs of multiple backends, whose key is the backend name. - Backends map[string]*BackendConfig `yaml:",omitempty,inline" json:",omitempty,inline"` -} - -// BackendConfig contains the type and configs of a backend, which is used to store Spec, State and Workspace. -type BackendConfig struct { - // Type is the backend type, supports BackendTypeLocal, BackendTypeOss, BackendTypeS3. - Type string `yaml:"type,omitempty" json:"type,omitempty"` - - // Configs contains config items of the backend, whose keys differ from different backend types. - Configs map[string]any `yaml:"configs,omitempty" json:"configs,omitempty"` -} - -// BackendLocalConfig contains the config of using local file system as backend, which can be converted -// from BackendConfig if Type is BackendTypeLocal. -type BackendLocalConfig struct { - // Path of the directory to store the files. - Path string `yaml:"path,omitempty" json:"path,omitempty"` -} - -// BackendOssConfig contains the config of using OSS as backend, which can be converted from BackendConfig -// if Type is BackendOssConfig. -type BackendOssConfig struct { - *GenericBackendObjectStorageConfig `yaml:",inline" json:",inline"` // OSS asks for non-empty endpoint -} - -// BackendS3Config contains the config of using S3 as backend, which can be converted from BackendConfig -// if Type is BackendS3Config. -type BackendS3Config struct { - *GenericBackendObjectStorageConfig `yaml:",inline" json:",inline"` - - // Region of S3. - Region string `yaml:"region,omitempty" json:"region,omitempty"` -} - -// GenericBackendObjectStorageConfig contains generic configs which can be reused by BackendOssConfig and -// BackendS3Config. -type GenericBackendObjectStorageConfig struct { - // Endpoint of the object storage service. - Endpoint string `yaml:"endpoint,omitempty" json:"endpoint,omitempty"` - - // AccessKeyID of the object storage service. - AccessKeyID string `yaml:"accessKeyID,omitempty" json:"accessKeyID,omitempty"` - - // AccessKeySecret of the object storage service. - AccessKeySecret string `yaml:"accessKeySecret,omitempty" json:"accessKeySecret,omitempty"` - - // Bucket of the object storage service. - Bucket string `yaml:"bucket" json:"bucket"` - - // Prefix of the key to store the files. - Prefix string `yaml:"prefix,omitempty" json:"prefix,omitempty"` -} - -// ToLocalBackend converts BackendConfig to structured BackendLocalConfig, works only when the Type -// is BackendTypeLocal, and the Configs are with correct type, or return nil. -func (b *BackendConfig) ToLocalBackend() *BackendLocalConfig { - if b.Type != BackendTypeLocal { - return nil - } - path, _ := b.Configs[BackendLocalPath].(string) - return &BackendLocalConfig{ - Path: path, - } -} - -// ToOssBackend converts BackendConfig to structured BackendOssConfig, works only when the Type is -// BackendTypeOss, and the Configs are with correct type, or return nil. -func (b *BackendConfig) ToOssBackend() *BackendOssConfig { - if b.Type != BackendTypeOss { - return nil - } - endpoint, _ := b.Configs[BackendGenericOssEndpoint].(string) - accessKeyID, _ := b.Configs[BackendGenericOssAK].(string) - accessKeySecret, _ := b.Configs[BackendGenericOssSK].(string) - bucket, _ := b.Configs[BackendGenericOssBucket].(string) - prefix, _ := b.Configs[BackendGenericOssPrefix].(string) - return &BackendOssConfig{ - &GenericBackendObjectStorageConfig{ - Endpoint: endpoint, - AccessKeyID: accessKeyID, - AccessKeySecret: accessKeySecret, - Bucket: bucket, - Prefix: prefix, - }, - } -} - -// ToS3Backend converts BackendConfig to structured BackendS3Config, works only when the Type is -// BackendTypeS3, and the Configs are with correct type, or return nil. -func (b *BackendConfig) ToS3Backend() *BackendS3Config { - if b.Type != BackendTypeS3 { - return nil - } - endpoint, _ := b.Configs[BackendGenericOssEndpoint].(string) - accessKeyID, _ := b.Configs[BackendGenericOssAK].(string) - accessKeySecret, _ := b.Configs[BackendGenericOssSK].(string) - bucket, _ := b.Configs[BackendGenericOssBucket].(string) - prefix, _ := b.Configs[BackendGenericOssPrefix].(string) - region, _ := b.Configs[BackendS3Region].(string) - return &BackendS3Config{ - GenericBackendObjectStorageConfig: &GenericBackendObjectStorageConfig{ - Endpoint: endpoint, - AccessKeyID: accessKeyID, - AccessKeySecret: accessKeySecret, - Bucket: bucket, - Prefix: prefix, - }, - Region: region, - } -} diff --git a/pkg/backend/backend.go b/pkg/backend/backend.go index a176d871..33ff3beb 100644 --- a/pkg/backend/backend.go +++ b/pkg/backend/backend.go @@ -3,7 +3,7 @@ package backend import ( "fmt" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" "kusionstack.io/kusion/pkg/backend/storages" "kusionstack.io/kusion/pkg/config" "kusionstack.io/kusion/pkg/engine/state" diff --git a/pkg/backend/backend_test.go b/pkg/backend/backend_test.go index 5209089c..0d4e58e9 100644 --- a/pkg/backend/backend_test.go +++ b/pkg/backend/backend_test.go @@ -8,7 +8,7 @@ import ( "github.com/bytedance/mockey" "github.com/stretchr/testify/assert" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" "kusionstack.io/kusion/pkg/backend/storages" "kusionstack.io/kusion/pkg/config" ) diff --git a/pkg/backend/storages/completion.go b/pkg/backend/storages/completion.go index 9c9e8ece..edb29c3c 100644 --- a/pkg/backend/storages/completion.go +++ b/pkg/backend/storages/completion.go @@ -3,7 +3,7 @@ package storages import ( "os" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" "kusionstack.io/kusion/pkg/util/kfile" ) diff --git a/pkg/backend/storages/completion_test.go b/pkg/backend/storages/completion_test.go index f395d8ac..93d7c465 100644 --- a/pkg/backend/storages/completion_test.go +++ b/pkg/backend/storages/completion_test.go @@ -7,7 +7,7 @@ import ( "github.com/bytedance/mockey" "github.com/stretchr/testify/assert" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" "kusionstack.io/kusion/pkg/util/kfile" ) diff --git a/pkg/backend/storages/local.go b/pkg/backend/storages/local.go index 95352bc5..ac62314e 100644 --- a/pkg/backend/storages/local.go +++ b/pkg/backend/storages/local.go @@ -1,7 +1,7 @@ package storages import ( - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" "kusionstack.io/kusion/pkg/engine/state" statestorages "kusionstack.io/kusion/pkg/engine/state/storages" "kusionstack.io/kusion/pkg/workspace" diff --git a/pkg/backend/storages/local_test.go b/pkg/backend/storages/local_test.go index f67a6114..b825b44c 100644 --- a/pkg/backend/storages/local_test.go +++ b/pkg/backend/storages/local_test.go @@ -7,7 +7,7 @@ import ( "github.com/bytedance/mockey" "github.com/stretchr/testify/assert" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" "kusionstack.io/kusion/pkg/engine/state" statestorages "kusionstack.io/kusion/pkg/engine/state/storages" "kusionstack.io/kusion/pkg/workspace" diff --git a/pkg/backend/storages/oss.go b/pkg/backend/storages/oss.go index e772afbc..50f0d162 100644 --- a/pkg/backend/storages/oss.go +++ b/pkg/backend/storages/oss.go @@ -3,7 +3,7 @@ package storages import ( "github.com/aliyun/aliyun-oss-go-sdk/oss" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" "kusionstack.io/kusion/pkg/engine/state" statestorages "kusionstack.io/kusion/pkg/engine/state/storages" "kusionstack.io/kusion/pkg/workspace" diff --git a/pkg/backend/storages/oss_test.go b/pkg/backend/storages/oss_test.go index 195103dc..c02bb759 100644 --- a/pkg/backend/storages/oss_test.go +++ b/pkg/backend/storages/oss_test.go @@ -7,7 +7,7 @@ import ( "github.com/bytedance/mockey" "github.com/stretchr/testify/assert" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" "kusionstack.io/kusion/pkg/engine/state" statestorages "kusionstack.io/kusion/pkg/engine/state/storages" workspacestorages "kusionstack.io/kusion/pkg/workspace/storages" diff --git a/pkg/backend/storages/s3.go b/pkg/backend/storages/s3.go index 1f688861..dd23f4c7 100644 --- a/pkg/backend/storages/s3.go +++ b/pkg/backend/storages/s3.go @@ -6,7 +6,7 @@ import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" "kusionstack.io/kusion/pkg/engine/state" statestorages "kusionstack.io/kusion/pkg/engine/state/storages" "kusionstack.io/kusion/pkg/workspace" diff --git a/pkg/backend/storages/s3_test.go b/pkg/backend/storages/s3_test.go index 96cba6ad..624b3c45 100644 --- a/pkg/backend/storages/s3_test.go +++ b/pkg/backend/storages/s3_test.go @@ -8,7 +8,7 @@ import ( "github.com/bytedance/mockey" "github.com/stretchr/testify/assert" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" "kusionstack.io/kusion/pkg/engine/state" statestorages "kusionstack.io/kusion/pkg/engine/state/storages" workspacestorages "kusionstack.io/kusion/pkg/workspace/storages" diff --git a/pkg/backend/storages/validation.go b/pkg/backend/storages/validation.go index 02e0c525..d11284a2 100644 --- a/pkg/backend/storages/validation.go +++ b/pkg/backend/storages/validation.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" ) var ( diff --git a/pkg/backend/storages/validation_test.go b/pkg/backend/storages/validation_test.go index 4e7aec4b..709aacbc 100644 --- a/pkg/backend/storages/validation_test.go +++ b/pkg/backend/storages/validation_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" ) func TestValidateOssConfig(t *testing.T) { diff --git a/pkg/cmd/apply/apply_test.go b/pkg/cmd/apply/apply_test.go index 5e18a46c..b3902439 100644 --- a/pkg/cmd/apply/apply_test.go +++ b/pkg/cmd/apply/apply_test.go @@ -26,7 +26,6 @@ import ( "github.com/stretchr/testify/assert" apiv1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" - internalv1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" v1 "kusionstack.io/kusion/pkg/apis/status/v1" "kusionstack.io/kusion/pkg/backend/storages" "kusionstack.io/kusion/pkg/cmd/generate" @@ -55,7 +54,7 @@ var ( ) func NewApplyOptions() *ApplyOptions { - storageBackend := storages.NewLocalStorage(&internalv1.BackendLocalConfig{ + storageBackend := storages.NewLocalStorage(&apiv1.BackendLocalConfig{ Path: filepath.Join("", "state.yaml"), }) return &ApplyOptions{ diff --git a/pkg/cmd/config/list/cmd_test.go b/pkg/cmd/config/list/cmd_test.go index 3b20e586..bd361f6f 100644 --- a/pkg/cmd/config/list/cmd_test.go +++ b/pkg/cmd/config/list/cmd_test.go @@ -6,7 +6,7 @@ import ( "github.com/bytedance/mockey" "github.com/stretchr/testify/assert" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" "kusionstack.io/kusion/pkg/config" ) diff --git a/pkg/cmd/destroy/destroy_test.go b/pkg/cmd/destroy/destroy_test.go index 5d069c5d..feb79a16 100644 --- a/pkg/cmd/destroy/destroy_test.go +++ b/pkg/cmd/destroy/destroy_test.go @@ -26,7 +26,6 @@ import ( "github.com/stretchr/testify/assert" apiv1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" - internalv1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" v1 "kusionstack.io/kusion/pkg/apis/status/v1" "kusionstack.io/kusion/pkg/backend" "kusionstack.io/kusion/pkg/backend/storages" @@ -56,7 +55,7 @@ var ( func NewDeleteOptions() *DeleteOptions { cwd, _ := os.Getwd() - storageBackend := storages.NewLocalStorage(&internalv1.BackendLocalConfig{ + storageBackend := storages.NewLocalStorage(&apiv1.BackendLocalConfig{ Path: filepath.Join(cwd, "state.yaml"), }) return &DeleteOptions{ diff --git a/pkg/cmd/preview/preview_test.go b/pkg/cmd/preview/preview_test.go index 6f49946e..7e70ba34 100644 --- a/pkg/cmd/preview/preview_test.go +++ b/pkg/cmd/preview/preview_test.go @@ -23,7 +23,6 @@ import ( "github.com/stretchr/testify/assert" apiv1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" - internalv1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" v1 "kusionstack.io/kusion/pkg/apis/status/v1" "kusionstack.io/kusion/pkg/backend/storages" "kusionstack.io/kusion/pkg/cmd/generate" @@ -59,7 +58,7 @@ var ( ) func NewPreviewOptions() *PreviewOptions { - storageBackend := storages.NewLocalStorage(&internalv1.BackendLocalConfig{ + storageBackend := storages.NewLocalStorage(&apiv1.BackendLocalConfig{ Path: filepath.Join("", "state.yaml"), }) return &PreviewOptions{ diff --git a/pkg/config/operator.go b/pkg/config/operator.go index bd8a8b08..04e6ca4c 100644 --- a/pkg/config/operator.go +++ b/pkg/config/operator.go @@ -12,7 +12,7 @@ import ( "gopkg.in/yaml.v3" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" "kusionstack.io/kusion/pkg/util/kfile" ) diff --git a/pkg/config/operator_test.go b/pkg/config/operator_test.go index a4b1e167..823cb143 100644 --- a/pkg/config/operator_test.go +++ b/pkg/config/operator_test.go @@ -8,7 +8,7 @@ import ( "github.com/bytedance/mockey" "github.com/stretchr/testify/assert" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" ) var ( diff --git a/pkg/config/registry.go b/pkg/config/registry.go index b08477fb..4012cd41 100644 --- a/pkg/config/registry.go +++ b/pkg/config/registry.go @@ -1,7 +1,7 @@ package config import ( - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" ) const ( diff --git a/pkg/config/util.go b/pkg/config/util.go index f0fa0e7f..b80cfb2d 100644 --- a/pkg/config/util.go +++ b/pkg/config/util.go @@ -1,7 +1,7 @@ package config import ( - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" ) // GetConfig returns the structured config stored in the config file. The validation of the config is not checked. diff --git a/pkg/config/util_test.go b/pkg/config/util_test.go index 8aa6c4b7..9c359c2f 100644 --- a/pkg/config/util_test.go +++ b/pkg/config/util_test.go @@ -6,7 +6,7 @@ import ( "github.com/bytedance/mockey" "github.com/stretchr/testify/assert" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" ) func mockNewOperator(config *v1.Config) { diff --git a/pkg/config/validation.go b/pkg/config/validation.go index 88bc9b1a..2b23a0d3 100644 --- a/pkg/config/validation.go +++ b/pkg/config/validation.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" "kusionstack.io/kusion/pkg/backend/storages" ) diff --git a/pkg/config/validation_test.go b/pkg/config/validation_test.go index 29ad3aa3..41a51fa5 100644 --- a/pkg/config/validation_test.go +++ b/pkg/config/validation_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/assert" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" ) func TestValidateSetCurrentBackend(t *testing.T) { diff --git a/pkg/domain/entity/backend.go b/pkg/domain/entity/backend.go index 7fa4bc63..5870e60b 100644 --- a/pkg/domain/entity/backend.go +++ b/pkg/domain/entity/backend.go @@ -3,7 +3,7 @@ package entity import ( "time" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" "kusionstack.io/kusion/pkg/domain/constant" ) diff --git a/pkg/domain/request/backend_request.go b/pkg/domain/request/backend_request.go index 103a3840..31e81636 100644 --- a/pkg/domain/request/backend_request.go +++ b/pkg/domain/request/backend_request.go @@ -1,6 +1,6 @@ package request -import v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" +import v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" // CreateBackendRequest represents the create request structure for // backend. diff --git a/pkg/engine/api/builders/appconfig_builder.go b/pkg/engine/api/builders/appconfig_builder.go index 59da34e3..77d21bb5 100644 --- a/pkg/engine/api/builders/appconfig_builder.go +++ b/pkg/engine/api/builders/appconfig_builder.go @@ -21,13 +21,12 @@ import ( "kcl-lang.io/kpm/pkg/api" v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" - internalv1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" "kusionstack.io/kusion/pkg/modules" "kusionstack.io/kusion/pkg/modules/generators" ) type AppsConfigBuilder struct { - Apps map[string]internalv1.AppConfiguration + Apps map[string]v1.AppConfiguration Workspace *v1.Workspace } @@ -37,7 +36,7 @@ func (acg *AppsConfigBuilder) Build(kclPackage *api.KclPackage, project *v1.Proj } var gfs []modules.NewGeneratorFunc - err := modules.ForeachOrdered(acg.Apps, func(appName string, app internalv1.AppConfiguration) error { + err := modules.ForeachOrdered(acg.Apps, func(appName string, app v1.AppConfiguration) error { if kclPackage == nil { return fmt.Errorf("kcl package is nil when generating app configuration for %s", appName) } diff --git a/pkg/engine/api/builders/appconfig_builder_test.go b/pkg/engine/api/builders/appconfig_builder_test.go index 8e6d305a..973b32e0 100644 --- a/pkg/engine/api/builders/appconfig_builder_test.go +++ b/pkg/engine/api/builders/appconfig_builder_test.go @@ -24,7 +24,6 @@ import ( "kcl-lang.io/kpm/pkg/api" v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" - internalv1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" "kusionstack.io/kusion/pkg/modules" ) @@ -32,7 +31,7 @@ func TestBuild(t *testing.T) { p, s := buildMockProjectAndStack() appName, app := buildMockApp() acg := &AppsConfigBuilder{ - Apps: map[string]internalv1.AppConfiguration{ + Apps: map[string]v1.AppConfiguration{ appName: *app, }, Workspace: buildMockWorkspace(), @@ -53,16 +52,16 @@ func TestBuild(t *testing.T) { assert.NotNil(t, intent) } -func buildMockApp() (string, *internalv1.AppConfiguration) { - return "app1", &internalv1.AppConfiguration{ - Workload: &internalv1.Workload{ - Header: internalv1.Header{ +func buildMockApp() (string, *v1.AppConfiguration) { + return "app1", &v1.AppConfiguration{ + Workload: &v1.Workload{ + Header: v1.Header{ Type: "Service", }, - Service: &internalv1.Service{ - Base: internalv1.Base{}, + Service: &v1.Service{ + Base: v1.Base{}, Type: "Deployment", - Ports: []internalv1.Port{ + Ports: []v1.Port{ { Port: 80, Protocol: "TCP", diff --git a/pkg/engine/api/generate/generator/generator.go b/pkg/engine/api/generate/generator/generator.go index 6f910ca5..3527bb58 100644 --- a/pkg/engine/api/generate/generator/generator.go +++ b/pkg/engine/api/generate/generator/generator.go @@ -27,7 +27,6 @@ import ( pkg "kcl-lang.io/kpm/pkg/package" v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" - internalv1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" "kusionstack.io/kusion/pkg/engine/api/builders" "kusionstack.io/kusion/pkg/engine/api/generate/run" "kusionstack.io/kusion/pkg/util/io" @@ -68,7 +67,7 @@ func (g *DefaultGenerator) Generate(workDir string, params map[string]string) (* // Note: we use the type of MapSlice in yaml.v2 to maintain the order of container // environment variables, thus we unmarshal appConfigs with yaml.v2 rather than yaml.v3. - apps := map[string]internalv1.AppConfiguration{} + apps := map[string]v1.AppConfiguration{} err = yaml.Unmarshal(rawAppConfiguration, apps) if err != nil { return nil, err diff --git a/pkg/infra/persistence/backend_model.go b/pkg/infra/persistence/backend_model.go index 2119d012..e08f00b8 100644 --- a/pkg/infra/persistence/backend_model.go +++ b/pkg/infra/persistence/backend_model.go @@ -1,7 +1,7 @@ package persistence import ( - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" "kusionstack.io/kusion/pkg/domain/entity" "gorm.io/gorm" diff --git a/pkg/infra/persistence/backend_test.go b/pkg/infra/persistence/backend_test.go index 9625b6e4..59d916d5 100644 --- a/pkg/infra/persistence/backend_test.go +++ b/pkg/infra/persistence/backend_test.go @@ -7,7 +7,8 @@ import ( "github.com/DATA-DOG/go-sqlmock" "github.com/stretchr/testify/require" "gorm.io/gorm" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" "kusionstack.io/kusion/pkg/domain/entity" ) diff --git a/pkg/modules/generators/app_configurations_generator.go b/pkg/modules/generators/app_configurations_generator.go index 4afcd6ef..2c82c002 100644 --- a/pkg/modules/generators/app_configurations_generator.go +++ b/pkg/modules/generators/app_configurations_generator.go @@ -13,7 +13,6 @@ import ( "kcl-lang.io/kpm/pkg/package" v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" - internalv1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" "kusionstack.io/kusion/pkg/log" "kusionstack.io/kusion/pkg/modules" "kusionstack.io/kusion/pkg/modules/generators/workload" @@ -25,7 +24,7 @@ type appConfigurationGenerator struct { project string stack string appName string - app *internalv1.AppConfiguration + app *v1.AppConfiguration ws *v1.Workspace dependencies *pkg.Dependencies } @@ -38,7 +37,7 @@ func NewAppConfigurationGenerator( project string, stack string, appName string, - app *internalv1.AppConfiguration, + app *v1.AppConfiguration, ws *v1.Workspace, dependencies *pkg.Dependencies, ) (modules.Generator, error) { @@ -80,7 +79,7 @@ func NewAppConfigurationGeneratorFunc( project string, stack string, appName string, - app *internalv1.AppConfiguration, + app *v1.AppConfiguration, ws *v1.Workspace, kpmDependencies *pkg.Dependencies, ) modules.NewGeneratorFunc { @@ -150,7 +149,7 @@ func (g *appConfigurationGenerator) Generate(spec *v1.Spec) error { return nil } -func PatchWorkload(workload *v1.Resource, patcher *internalv1.Patcher) error { +func PatchWorkload(workload *v1.Resource, patcher *v1.Patcher) error { if patcher == nil { return nil } @@ -251,12 +250,12 @@ func PatchWorkload(workload *v1.Resource, patcher *internalv1.Patcher) error { // moduleConfig represents the configuration of a module, either devConfig or platformConfig can be nil type moduleConfig struct { - devConfig internalv1.Accessory + devConfig v1.Accessory platformConfig v1.GenericConfig ctx v1.GenericConfig } -func (g *appConfigurationGenerator) callModules(projectModuleConfigs map[string]v1.GenericConfig) (resources []v1.Resource, patchers []internalv1.Patcher, err error) { +func (g *appConfigurationGenerator) callModules(projectModuleConfigs map[string]v1.GenericConfig) (resources []v1.Resource, patchers []v1.Patcher, err error) { pluginMap := make(map[string]*modules.Plugin) defer func() { for _, plugin := range pluginMap { @@ -324,7 +323,7 @@ func (g *appConfigurationGenerator) callModules(projectModuleConfigs map[string] // parse patcher for _, patcher := range response.Patchers { - temp := &internalv1.Patcher{} + temp := &v1.Patcher{} err = yaml.Unmarshal(patcher, temp) if err != nil { return nil, nil, err @@ -364,7 +363,7 @@ func (g *appConfigurationGenerator) buildModuleConfigIndex(platformModuleConfigs return indexModuleConfig, nil } -func parseModuleKey(accessory internalv1.Accessory, dependencies *pkg.Dependencies) (string, error) { +func parseModuleKey(accessory v1.Accessory, dependencies *pkg.Dependencies) (string, error) { split := strings.Split(accessory["_type"].(string), ".") moduleName := split[0] // find module namespace and version diff --git a/pkg/modules/generators/app_configurations_generator_test.go b/pkg/modules/generators/app_configurations_generator_test.go index 4b99b561..b9f0e87a 100644 --- a/pkg/modules/generators/app_configurations_generator_test.go +++ b/pkg/modules/generators/app_configurations_generator_test.go @@ -16,7 +16,6 @@ import ( pkg "kcl-lang.io/kpm/pkg/package" v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" - internalv1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" "kusionstack.io/kusion/pkg/modules" "kusionstack.io/kusion/pkg/modules/proto" jsonutil "kusionstack.io/kusion/pkg/util/json" @@ -160,16 +159,16 @@ func TestNewAppConfigurationGeneratorFunc(t *testing.T) { }) } -func buildMockApp() (string, *internalv1.AppConfiguration) { - return "app1", &internalv1.AppConfiguration{ - Workload: &internalv1.Workload{ - Header: internalv1.Header{ - Type: internalv1.TypeService, +func buildMockApp() (string, *v1.AppConfiguration) { + return "app1", &v1.AppConfiguration{ + Workload: &v1.Workload{ + Header: v1.Header{ + Type: v1.TypeService, }, - Service: &internalv1.Service{ - Base: internalv1.Base{}, + Service: &v1.Service{ + Base: v1.Base{}, Type: "Deployment", - Ports: []internalv1.Port{ + Ports: []v1.Port{ { Port: 80, Protocol: "TCP", @@ -291,7 +290,7 @@ func Test_patchWorkload(t *testing.T) { } t.Run("Patch labels and annotations", func(t *testing.T) { - patcher := &internalv1.Patcher{ + patcher := &v1.Patcher{ Labels: map[string]string{"newLabel": "newValue"}, Annotations: map[string]string{"newAnnotation": "newValue"}, } @@ -320,7 +319,7 @@ func Test_patchWorkload(t *testing.T) { }) t.Run("Patch environment variables", func(t *testing.T) { - patcher := &internalv1.Patcher{ + patcher := &v1.Patcher{ Environments: []corev1.EnvVar{ { Name: "NEW_ENV", diff --git a/pkg/modules/generators/workload/job_generator.go b/pkg/modules/generators/workload/job_generator.go index 106cb93f..573edcd1 100644 --- a/pkg/modules/generators/workload/job_generator.go +++ b/pkg/modules/generators/workload/job_generator.go @@ -8,7 +8,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" - internalv1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" "kusionstack.io/kusion/pkg/modules" ) @@ -16,7 +15,7 @@ type jobGenerator struct { project string stack string appName string - job *internalv1.Job + job *v1.Job jobConfig v1.GenericConfig namespace string } @@ -27,7 +26,7 @@ func NewJobGenerator(generator *Generator) (modules.Generator, error) { stack: generator.Stack, appName: generator.App, job: generator.Workload.Job, - jobConfig: generator.PlatformConfigs[internalv1.ModuleJob], + jobConfig: generator.PlatformConfigs[v1.ModuleJob], namespace: generator.Namespace, }, nil } diff --git a/pkg/modules/generators/workload/job_generator_test.go b/pkg/modules/generators/workload/job_generator_test.go index ae49b691..4d425838 100644 --- a/pkg/modules/generators/workload/job_generator_test.go +++ b/pkg/modules/generators/workload/job_generator_test.go @@ -7,7 +7,6 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" - internalv1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" "kusionstack.io/kusion/pkg/modules" ) @@ -15,7 +14,7 @@ func TestNewJobGenerator(t *testing.T) { expectedProject := "test" expectedStack := "dev" expectedAppName := "test" - expectedJob := &internalv1.Job{} + expectedJob := &v1.Job{} expectedJobConfig := v1.GenericConfig{ "labels": v1.GenericConfig{ "Workload-type": "Job", @@ -29,11 +28,11 @@ func TestNewJobGenerator(t *testing.T) { Stack: expectedStack, App: expectedAppName, Namespace: expectedAppName, - Workload: &internalv1.Workload{ + Workload: &v1.Workload{ Job: expectedJob, }, PlatformConfigs: map[string]v1.GenericConfig{ - internalv1.ModuleJob: expectedJobConfig, + v1.ModuleJob: expectedJobConfig, }, }) @@ -50,7 +49,7 @@ func TestNewJobGeneratorFunc(t *testing.T) { expectedProject := "test" expectedStack := "dev" expectedAppName := "test" - expectedJob := &internalv1.Job{} + expectedJob := &v1.Job{} expectedJobConfig := v1.GenericConfig{ "labels": v1.GenericConfig{ "workload-type": "Job", @@ -64,11 +63,11 @@ func TestNewJobGeneratorFunc(t *testing.T) { Stack: expectedStack, App: expectedAppName, Namespace: expectedAppName, - Workload: &internalv1.Workload{ + Workload: &v1.Workload{ Job: expectedJob, }, PlatformConfigs: map[string]v1.GenericConfig{ - internalv1.ModuleJob: expectedJobConfig, + v1.ModuleJob: expectedJobConfig, }, }) actualGenerator, err := generatorFunc() @@ -88,7 +87,7 @@ func TestJobGenerator_Generate(t *testing.T) { expectedProject string expectedStack string expectedAppName string - expectedJob *internalv1.Job + expectedJob *v1.Job expectedJobConfig v1.GenericConfig }{ { @@ -96,7 +95,7 @@ func TestJobGenerator_Generate(t *testing.T) { expectedProject: "test", expectedStack: "dev", expectedAppName: "test", - expectedJob: &internalv1.Job{}, + expectedJob: &v1.Job{}, expectedJobConfig: v1.GenericConfig{ "labels": v1.GenericConfig{ "workload-type": "Job", @@ -115,11 +114,11 @@ func TestJobGenerator_Generate(t *testing.T) { Stack: tc.expectedStack, App: tc.expectedAppName, Namespace: tc.expectedAppName, - Workload: &internalv1.Workload{ + Workload: &v1.Workload{ Job: tc.expectedJob, }, PlatformConfigs: map[string]v1.GenericConfig{ - internalv1.ModuleJob: tc.expectedJobConfig, + v1.ModuleJob: tc.expectedJobConfig, }, }) spec := &v1.Spec{} diff --git a/pkg/modules/generators/workload/secret/secret_generator.go b/pkg/modules/generators/workload/secret/secret_generator.go index 20bcdbbb..3ad4e059 100644 --- a/pkg/modules/generators/workload/secret/secret_generator.go +++ b/pkg/modules/generators/workload/secret/secret_generator.go @@ -13,7 +13,6 @@ import ( utilerrors "k8s.io/apimachinery/pkg/util/errors" v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" - internalv1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" "kusionstack.io/kusion/pkg/modules" "kusionstack.io/kusion/pkg/secrets" ) @@ -21,7 +20,7 @@ import ( type secretGenerator struct { project string namespace string - secrets map[string]internalv1.Secret + secrets map[string]v1.Secret secretStoreSpec *v1.SecretStoreSpec } @@ -31,7 +30,7 @@ type GeneratorRequest struct { // Namespace represents the K8s Namespace Namespace string // Workload represents the Workload configuration - Workload *internalv1.Workload + Workload *v1.Workload // SecretStoreSpec contains configuration to describe target secret store. SecretStoreSpec *v1.SecretStoreSpec } @@ -41,7 +40,7 @@ func NewSecretGenerator(request *GeneratorRequest) (modules.Generator, error) { return nil, fmt.Errorf("project name must not be empty") } - var secretMap map[string]internalv1.Secret + var secretMap map[string]v1.Secret if request.Workload.Service != nil { secretMap = request.Workload.Service.Secrets } else { @@ -91,7 +90,7 @@ func (g *secretGenerator) Generate(spec *v1.Spec) error { // generateSecret generates target secret based on secret type. Most of these secret types are just semantic wrapper // of native Kubernetes secret types:https://kubernetes.io/docs/concepts/configuration/secret/#secret-types, and more // detailed usage info can be found in public documentation. -func (g *secretGenerator) generateSecret(secretName string, secretRef internalv1.Secret) (*corev1.Secret, error) { +func (g *secretGenerator) generateSecret(secretName string, secretRef v1.Secret) (*corev1.Secret, error) { switch secretRef.Type { case "basic": return g.generateBasic(secretName, secretRef) @@ -110,7 +109,7 @@ func (g *secretGenerator) generateSecret(secretName string, secretRef internalv1 // generateBasic generates secret used for basic authentication. The basic secret type // is used for username / password pairs. -func (g *secretGenerator) generateBasic(secretName string, secretRef internalv1.Secret) (*corev1.Secret, error) { +func (g *secretGenerator) generateBasic(secretName string, secretRef v1.Secret) (*corev1.Secret, error) { secret := initBasicSecret(g.namespace, secretName, corev1.SecretTypeBasicAuth, secretRef.Immutable) secret.Data = grabData(secretRef.Data, corev1.BasicAuthUsernameKey, corev1.BasicAuthPasswordKey) @@ -126,7 +125,7 @@ func (g *secretGenerator) generateBasic(secretName string, secretRef internalv1. // generateToken generates secret used for password. Token secrets are useful for generating // a password or secure string used for passwords when the user is already known or not required. -func (g *secretGenerator) generateToken(secretName string, secretRef internalv1.Secret) (*corev1.Secret, error) { +func (g *secretGenerator) generateToken(secretName string, secretRef v1.Secret) (*corev1.Secret, error) { secret := initBasicSecret(g.namespace, secretName, corev1.SecretTypeOpaque, secretRef.Immutable) secret.Data = grabData(secretRef.Data, "token") @@ -139,7 +138,7 @@ func (g *secretGenerator) generateToken(secretName string, secretRef internalv1. } // generateOpaque generates secret used for arbitrary user-defined data. -func (g *secretGenerator) generateOpaque(secretName string, secretRef internalv1.Secret) (*corev1.Secret, error) { +func (g *secretGenerator) generateOpaque(secretName string, secretRef v1.Secret) (*corev1.Secret, error) { secret := initBasicSecret(g.namespace, secretName, corev1.SecretTypeOpaque, secretRef.Immutable) secret.Data = grabData(secretRef.Data, maps.Keys(secretRef.Data)...) return secret, nil @@ -147,8 +146,8 @@ func (g *secretGenerator) generateOpaque(secretName string, secretRef internalv1 // generateCertificate generates secret used for storing a certificate and its associated key. // One common use for TLS Secrets is to configure encryption in transit for an Ingress, but -// you can also use it with other resources or directly in your internalv1. -func (g *secretGenerator) generateCertificate(secretName string, secretRef internalv1.Secret) (*corev1.Secret, error) { +// you can also use it with other resources or directly in your v1. +func (g *secretGenerator) generateCertificate(secretName string, secretRef v1.Secret) (*corev1.Secret, error) { secret := initBasicSecret(g.namespace, secretName, corev1.SecretTypeTLS, secretRef.Immutable) secret.Data = grabData(secretRef.Data, corev1.TLSCertKey, corev1.TLSPrivateKeyKey) return secret, nil @@ -156,7 +155,7 @@ func (g *secretGenerator) generateCertificate(secretName string, secretRef inter // generateSecretWithExternalProvider retrieves target sensitive information from external secret provider and // generates corresponding Kubernetes Secret object. -func (g *secretGenerator) generateSecretWithExternalProvider(secretName string, secretRef internalv1.Secret) (*corev1.Secret, error) { +func (g *secretGenerator) generateSecretWithExternalProvider(secretName string, secretRef v1.Secret) (*corev1.Secret, error) { if g.secretStoreSpec == nil { return nil, errors.New("secret store is missing, please add valid secret store spec in workspace") } diff --git a/pkg/modules/generators/workload/secret/secret_generator_test.go b/pkg/modules/generators/workload/secret/secret_generator_test.go index a2b5423e..fbe4ea0a 100644 --- a/pkg/modules/generators/workload/secret/secret_generator_test.go +++ b/pkg/modules/generators/workload/secret/secret_generator_test.go @@ -7,7 +7,6 @@ import ( "github.com/stretchr/testify/require" v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" - internalv1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" // ensure we can get correct secret store provider _ "kusionstack.io/kusion/pkg/secrets/providers/register" ) @@ -16,14 +15,14 @@ var testProject = "helloworld" func initGeneratorRequest( project string, - secrets map[string]internalv1.Secret, + secrets map[string]v1.Secret, secretStoreSpec *v1.SecretStoreSpec, ) *GeneratorRequest { return &GeneratorRequest{ Project: project, - Workload: &internalv1.Workload{ - Service: &internalv1.Service{ - Base: internalv1.Base{ + Workload: &v1.Workload{ + Service: &v1.Service{ + Base: v1.Base{ Secrets: secrets, }, }, @@ -106,7 +105,7 @@ func TestGenerateSecret(t *testing.T) { // run all the tests for name, test := range tests { t.Run(name, func(t *testing.T) { - secrets := map[string]internalv1.Secret{ + secrets := map[string]v1.Secret{ name: { Type: test.secretType, Data: test.secretData, @@ -170,7 +169,7 @@ func TestGenerateSecretWithExternalRef(t *testing.T) { // run all the tests for name, test := range tests { t.Run(name, func(t *testing.T) { - secrets := map[string]internalv1.Secret{ + secrets := map[string]v1.Secret{ name: { Type: test.secretType, Data: test.secretData, diff --git a/pkg/modules/generators/workload/service_generator.go b/pkg/modules/generators/workload/service_generator.go index 8fc5ea5c..43e52659 100644 --- a/pkg/modules/generators/workload/service_generator.go +++ b/pkg/modules/generators/workload/service_generator.go @@ -10,7 +10,6 @@ import ( "kusionstack.io/kube-api/apps/v1alpha1" apiv1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" - internalv1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" "kusionstack.io/kusion/pkg/modules" "kusionstack.io/kusion/pkg/workspace" ) @@ -29,7 +28,7 @@ type ServiceGenerator struct { Stack string App string Namespace string - Service *internalv1.Service + Service *apiv1.Service Config apiv1.GenericConfig } @@ -52,7 +51,7 @@ func NewWorkloadServiceGenerator(request *Generator) (modules.Generator, error) Stack: request.Stack, App: request.App, Service: request.Workload.Service, - Config: request.PlatformConfigs[internalv1.ModuleService], + Config: request.PlatformConfigs[apiv1.ModuleService], Namespace: request.Namespace, }, nil } @@ -130,10 +129,10 @@ func (g *ServiceGenerator) Generate(spec *apiv1.Spec) error { typeMeta := metav1.TypeMeta{} switch service.Type { - case internalv1.Deployment: + case apiv1.Deployment: typeMeta = metav1.TypeMeta{ APIVersion: appsv1.SchemeGroupVersion.String(), - Kind: string(internalv1.Deployment), + Kind: string(apiv1.Deployment), } spec := appsv1.DeploymentSpec{ Replicas: service.Replicas, @@ -145,10 +144,10 @@ func (g *ServiceGenerator) Generate(spec *apiv1.Spec) error { ObjectMeta: objectMeta, Spec: spec, } - case internalv1.Collaset: + case apiv1.Collaset: typeMeta = metav1.TypeMeta{ APIVersion: v1alpha1.GroupVersion.String(), - Kind: string(internalv1.Collaset), + Kind: string(apiv1.Collaset), } resource = &v1alpha1.CollaSet{ TypeMeta: typeMeta, @@ -178,7 +177,7 @@ func (g *ServiceGenerator) Generate(spec *apiv1.Spec) error { return nil } -func validatePorts(ports []internalv1.Port) error { +func validatePorts(ports []apiv1.Port) error { portProtocolRecord := make(map[string]struct{}) for _, port := range ports { if err := validatePort(&port); err != nil { @@ -195,20 +194,20 @@ func validatePorts(ports []internalv1.Port) error { return nil } -func validatePort(port *internalv1.Port) error { +func validatePort(port *apiv1.Port) error { if port.Port < 1 || port.Port > 65535 { return ErrInvalidPort } if port.TargetPort < 0 || port.Port > 65535 { return ErrInvalidTargetPort } - if port.Protocol != internalv1.TCP && port.Protocol != internalv1.UDP { + if port.Protocol != apiv1.TCP && port.Protocol != apiv1.UDP { return ErrInvalidProtocol } return nil } -func validate(selectors map[string]string, ports []internalv1.Port) error { +func validate(selectors map[string]string, ports []apiv1.Port) error { if len(selectors) == 0 { return ErrEmptySelectors } @@ -218,7 +217,7 @@ func validate(selectors map[string]string, ports []internalv1.Port) error { return nil } -func complete(ports []internalv1.Port) error { +func complete(ports []apiv1.Port) error { for i := range ports { if ports[i].TargetPort == 0 { ports[i].TargetPort = ports[i].Port @@ -227,20 +226,20 @@ func complete(ports []internalv1.Port) error { return nil } -func completeServiceInput(service *internalv1.Service, config apiv1.GenericConfig) error { +func completeServiceInput(service *apiv1.Service, config apiv1.GenericConfig) error { if err := completeBaseWorkload(&service.Base, config); err != nil { return err } - serviceTypeStr, err := workspace.GetStringFromGenericConfig(config, internalv1.ModuleServiceType) - platformServiceType := internalv1.ServiceType(serviceTypeStr) + serviceTypeStr, err := workspace.GetStringFromGenericConfig(config, apiv1.ModuleServiceType) + platformServiceType := apiv1.ServiceType(serviceTypeStr) if err != nil { return err } // if not set in workspace, use Deployment as default type if platformServiceType == "" { - platformServiceType = internalv1.Deployment + platformServiceType = apiv1.Deployment } - if platformServiceType != internalv1.Deployment && platformServiceType != internalv1.Collaset { + if platformServiceType != apiv1.Deployment && platformServiceType != apiv1.Collaset { return fmt.Errorf("unsupported Service type %s", platformServiceType) } if service.Type == "" { diff --git a/pkg/modules/generators/workload/service_generator_test.go b/pkg/modules/generators/workload/service_generator_test.go index 1f2f03f7..29917be4 100644 --- a/pkg/modules/generators/workload/service_generator_test.go +++ b/pkg/modules/generators/workload/service_generator_test.go @@ -9,7 +9,6 @@ import ( "gopkg.in/yaml.v3" v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" - internalv1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" ) func Test_workloadServiceGenerator_Generate(t *testing.T) { @@ -166,7 +165,7 @@ status: {} project string stack string appName string - service *internalv1.Service + service *v1.Service serviceConfig v1.GenericConfig } type args struct { @@ -186,12 +185,12 @@ status: {} project: "default", stack: "dev", appName: "foo", - service: &internalv1.Service{ - Base: internalv1.Base{ - Containers: map[string]internalv1.Container{ + service: &v1.Service{ + Base: v1.Base{ + Containers: map[string]v1.Container{ "nginx": { Image: "nginx:v1", - Files: map[string]internalv1.FileSpec{ + Files: map[string]v1.FileSpec{ "/tmp/example.txt": { Content: "some file contents", Mode: "0777", @@ -201,7 +200,7 @@ status: {} }, Replicas: r2, }, - Ports: []internalv1.Port{ + Ports: []v1.Port{ { Port: 80, Protocol: "TCP", @@ -230,12 +229,12 @@ status: {} project: "default", stack: "dev", appName: "foo", - service: &internalv1.Service{ - Base: internalv1.Base{ - Containers: map[string]internalv1.Container{ + service: &v1.Service{ + Base: v1.Base{ + Containers: map[string]v1.Container{ "nginx": { Image: "nginx:v1", - Files: map[string]internalv1.FileSpec{ + Files: map[string]v1.FileSpec{ "/tmp/example.txt": { Content: "some file contents", Mode: "0777", @@ -244,7 +243,7 @@ status: {} }, }, }, - Ports: []internalv1.Port{ + Ports: []v1.Port{ { Port: 80, Protocol: "TCP", @@ -292,16 +291,16 @@ func TestCompleteServiceInput(t *testing.T) { testcases := []struct { name string - service *internalv1.Service + service *v1.Service config v1.GenericConfig success bool - completedService *internalv1.Service + completedService *v1.Service }{ { name: "use type in workspace config", - service: &internalv1.Service{ - Base: internalv1.Base{ - Containers: map[string]internalv1.Container{ + service: &v1.Service{ + Base: v1.Base{ + Containers: map[string]v1.Container{ "nginx": { Image: "nginx:v1", }, @@ -319,9 +318,9 @@ func TestCompleteServiceInput(t *testing.T) { "type": "CollaSet", }, success: true, - completedService: &internalv1.Service{ - Base: internalv1.Base{ - Containers: map[string]internalv1.Container{ + completedService: &v1.Service{ + Base: v1.Base{ + Containers: map[string]v1.Container{ "nginx": { Image: "nginx:v1", }, @@ -339,9 +338,9 @@ func TestCompleteServiceInput(t *testing.T) { }, { name: "use default type", - service: &internalv1.Service{ - Base: internalv1.Base{ - Containers: map[string]internalv1.Container{ + service: &v1.Service{ + Base: v1.Base{ + Containers: map[string]v1.Container{ "nginx": { Image: "nginx:v1", }, @@ -357,9 +356,9 @@ func TestCompleteServiceInput(t *testing.T) { }, config: nil, success: true, - completedService: &internalv1.Service{ - Base: internalv1.Base{ - Containers: map[string]internalv1.Container{ + completedService: &v1.Service{ + Base: v1.Base{ + Containers: map[string]v1.Container{ "nginx": { Image: "nginx:v1", }, @@ -377,9 +376,9 @@ func TestCompleteServiceInput(t *testing.T) { }, { name: "invalid field type", - service: &internalv1.Service{ - Base: internalv1.Base{ - Containers: map[string]internalv1.Container{ + service: &v1.Service{ + Base: v1.Base{ + Containers: map[string]v1.Container{ "nginx": { Image: "nginx:v1", }, @@ -401,9 +400,9 @@ func TestCompleteServiceInput(t *testing.T) { }, { name: "unsupported type", - service: &internalv1.Service{ - Base: internalv1.Base{ - Containers: map[string]internalv1.Container{ + service: &v1.Service{ + Base: v1.Base{ + Containers: map[string]v1.Container{ "nginx": { Image: "nginx:v1", }, diff --git a/pkg/modules/generators/workload/workload_generator.go b/pkg/modules/generators/workload/workload_generator.go index 40514327..ef4aa633 100644 --- a/pkg/modules/generators/workload/workload_generator.go +++ b/pkg/modules/generators/workload/workload_generator.go @@ -15,7 +15,6 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" - internalv1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" "kusionstack.io/kusion/pkg/modules" "kusionstack.io/kusion/pkg/modules/generators/workload/secret" "kusionstack.io/kusion/pkg/util/net" @@ -32,7 +31,7 @@ type Generator struct { // Namespace represents the K8s Namespace Namespace string // Workload represents the Workload configuration - Workload *internalv1.Workload + Workload *v1.Workload // PlatformConfigs represents the module platform configurations PlatformConfigs map[string]v1.GenericConfig // SecretStoreSpec contains configuration to describe target secret store. @@ -66,14 +65,14 @@ func (g *Generator) Generate(spec *v1.Spec) error { var gfs []modules.NewGeneratorFunc switch g.Workload.Header.Type { - case internalv1.TypeService: + case v1.TypeService: gfs = append(gfs, NewWorkloadServiceGeneratorFunc(g), secret.NewSecretGeneratorFunc(&secret.GeneratorRequest{ Project: g.Project, Namespace: g.Namespace, Workload: g.Workload, SecretStoreSpec: g.SecretStoreSpec, })) - case internalv1.TypeJob: + case v1.TypeJob: gfs = append(gfs, NewJobGeneratorFunc(g), secret.NewSecretGeneratorFunc(&secret.GeneratorRequest{ Project: g.Project, Namespace: g.Namespace, @@ -91,7 +90,7 @@ func (g *Generator) Generate(spec *v1.Spec) error { } func toOrderedContainers( - appContainers map[string]internalv1.Container, + appContainers map[string]v1.Container, uniqueAppName string, ) ([]corev1.Container, []corev1.Volume, []corev1.ConfigMap, error) { // Create a slice of containers based on the App's containers. @@ -102,7 +101,7 @@ func toOrderedContainers( var volumeMounts []corev1.VolumeMount var configMaps []corev1.ConfigMap - if err := modules.ForeachOrdered(appContainers, func(containerName string, c internalv1.Container) error { + if err := modules.ForeachOrdered(appContainers, func(containerName string, c v1.Container) error { // Create a slice of env vars based on the container's env vars. var envs []corev1.EnvVar for _, m := range c.Env { @@ -153,7 +152,7 @@ func toOrderedContainers( } // updateContainer updates corev1.Container with passed parameters. -func updateContainer(in *internalv1.Container, out *corev1.Container) error { +func updateContainer(in *v1.Container, out *corev1.Container) error { if in.ReadinessProbe != nil { readinessProbe, err := convertKusionProbeToV1Probe(in.ReadinessProbe) if err != nil { @@ -244,7 +243,7 @@ func populateResourceLists(name corev1.ResourceName, spec string) (corev1.Resour } // convertKusionProbeToV1Probe converts Kusion Probe to Kubernetes Probe types. -func convertKusionProbeToV1Probe(p *internalv1.Probe) (*corev1.Probe, error) { +func convertKusionProbeToV1Probe(p *v1.Probe) (*corev1.Probe, error) { result := &corev1.Probe{ InitialDelaySeconds: p.InitialDelaySeconds, TimeoutSeconds: p.TimeoutSeconds, @@ -273,7 +272,7 @@ func convertKusionProbeToV1Probe(p *internalv1.Probe) (*corev1.Probe, error) { } // convertKusionLifecycleToV1Lifecycle converts Kusion Lifecycle to Kubernetes Lifecycle types. -func convertKusionLifecycleToV1Lifecycle(l *internalv1.Lifecycle) (*corev1.Lifecycle, error) { +func convertKusionLifecycleToV1Lifecycle(l *v1.Lifecycle) (*corev1.Lifecycle, error) { result := &corev1.Lifecycle{} if l.PreStop != nil { preStop, err := lifecycleHandler(l.PreStop) @@ -292,7 +291,7 @@ func convertKusionLifecycleToV1Lifecycle(l *internalv1.Lifecycle) (*corev1.Lifec return result, nil } -func lifecycleHandler(in *internalv1.LifecycleHandler) (*corev1.LifecycleHandler, error) { +func lifecycleHandler(in *v1.LifecycleHandler) (*corev1.LifecycleHandler, error) { result := &corev1.LifecycleHandler{} switch in.Type { case "Http": @@ -349,14 +348,14 @@ func tcpSocketAction(urlstr string) (*corev1.TCPSocketAction, error) { // handleFileCreation handles the creation of the files declared in container.Files // and returns the generated ConfigMap, Volume and VolumeMount. -func handleFileCreation(c internalv1.Container, uniqueAppName, containerName string) ( +func handleFileCreation(c v1.Container, uniqueAppName, containerName string) ( volumes []corev1.Volume, volumeMounts []corev1.VolumeMount, configMaps []corev1.ConfigMap, err error, ) { var idx int - err = modules.ForeachOrdered(c.Files, func(k string, v internalv1.FileSpec) error { + err = modules.ForeachOrdered(c.Files, func(k string, v v1.FileSpec) error { // The declared file path needs to include the file name. if filepath.Base(k) == "." || filepath.Base(k) == "/" { return fmt.Errorf("the declared file path needs to include the file name") @@ -435,7 +434,7 @@ func handleFileCreation(c internalv1.Container, uniqueAppName, containerName str // handleDirCreation handles the creation of folder declared in container.Dirs and returns // the generated Volume and VolumeMount. -func handleDirCreation(c internalv1.Container) (volumes []corev1.Volume, volumeMounts []corev1.VolumeMount, err error) { +func handleDirCreation(c v1.Container) (volumes []corev1.Volume, volumeMounts []corev1.VolumeMount, err error) { err = modules.ForeachOrdered(c.Dirs, func(mountPath string, v string) error { sec, ok, parseErr := parseSecretReference(v) if parseErr != nil || !ok { @@ -461,8 +460,8 @@ func handleDirCreation(c internalv1.Container) (volumes []corev1.Volume, volumeM } // completeBaseWorkload uses config from workspace to complete the Workload base config. -func completeBaseWorkload(base *internalv1.Base, config v1.GenericConfig) error { - replicas, err := workspace.GetInt32PointerFromGenericConfig(config, internalv1.FieldReplicas) +func completeBaseWorkload(base *v1.Base, config v1.GenericConfig) error { + replicas, err := workspace.GetInt32PointerFromGenericConfig(config, v1.FieldReplicas) if err != nil { return err } @@ -471,7 +470,7 @@ func completeBaseWorkload(base *internalv1.Base, config v1.GenericConfig) error if base.Replicas == nil { base.Replicas = replicas } - labels, err := workspace.GetStringMapFromGenericConfig(config, internalv1.FieldLabels) + labels, err := workspace.GetStringMapFromGenericConfig(config, v1.FieldLabels) if err != nil { return err } @@ -480,7 +479,7 @@ func completeBaseWorkload(base *internalv1.Base, config v1.GenericConfig) error return err } } - annotations, err := workspace.GetStringMapFromGenericConfig(config, internalv1.FieldAnnotations) + annotations, err := workspace.GetStringMapFromGenericConfig(config, v1.FieldAnnotations) if err != nil { return err } diff --git a/pkg/modules/generators/workload/workload_generator_test.go b/pkg/modules/generators/workload/workload_generator_test.go index 522788e8..269fec58 100644 --- a/pkg/modules/generators/workload/workload_generator_test.go +++ b/pkg/modules/generators/workload/workload_generator_test.go @@ -8,13 +8,12 @@ import ( "gopkg.in/yaml.v2" v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" - internalv1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" "kusionstack.io/kusion/pkg/modules" ) func TestNewWorkloadGeneratorFunc(t *testing.T) { t.Run("NewWorkloadGeneratorFunc should return a valid generator function", func(t *testing.T) { - expectedWorkload := &internalv1.Workload{} + expectedWorkload := &v1.Workload{} expectedAppName := "test" expectedProject := "test" expectedStack := "test" @@ -50,17 +49,17 @@ func TestNewWorkloadGeneratorFunc(t *testing.T) { func TestWorkloadGenerator_Generate(t *testing.T) { testCases := []struct { name string - expectedWorkload *internalv1.Workload + expectedWorkload *v1.Workload }{ { name: "Generate should generate the expected service", - expectedWorkload: &internalv1.Workload{ - Header: internalv1.Header{ - Type: internalv1.TypeService, + expectedWorkload: &v1.Workload{ + Header: v1.Header{ + Type: v1.TypeService, }, - Service: &internalv1.Service{ - Base: internalv1.Base{}, - Ports: []internalv1.Port{ + Service: &v1.Service{ + Base: v1.Base{}, + Ports: []v1.Port{ { Port: 80, Protocol: "TCP", @@ -71,12 +70,12 @@ func TestWorkloadGenerator_Generate(t *testing.T) { }, { name: "Generate should generate the expected job", - expectedWorkload: &internalv1.Workload{ - Header: internalv1.Header{ - Type: internalv1.TypeJob, + expectedWorkload: &v1.Workload{ + Header: v1.Header{ + Type: v1.TypeJob, }, - Job: &internalv1.Job{ - Base: internalv1.Base{}, + Job: &v1.Job{ + Base: v1.Base{}, Schedule: "* * * * *", }, }, @@ -137,23 +136,23 @@ func TestGenerate(t *testing.T) { project string stack string application string - workload *internalv1.Workload + workload *v1.Workload }{ { name: "simple service workload", project: "helloworld", stack: "dev", application: "nginx", - workload: &internalv1.Workload{ - Header: internalv1.Header{ - Type: internalv1.TypeService, + workload: &v1.Workload{ + Header: v1.Header{ + Type: v1.TypeService, }, - Service: &internalv1.Service{ - Base: internalv1.Base{ - Containers: map[string]internalv1.Container{ + Service: &v1.Service{ + Base: v1.Base{ + Containers: map[string]v1.Container{ "main": { Image: "nginx:latest", - Files: map[string]internalv1.FileSpec{ + Files: map[string]v1.FileSpec{ "/run/secret/password": { ContentFrom: "secret://sec-name/key?mode=0400", Mode: "0644", @@ -162,7 +161,7 @@ func TestGenerate(t *testing.T) { }, }, }, - Type: internalv1.Deployment, + Type: v1.Deployment, }, }, }, @@ -171,19 +170,19 @@ func TestGenerate(t *testing.T) { project: "beep", stack: "test", application: "nginx", - workload: &internalv1.Workload{ - Header: internalv1.Header{ - Type: internalv1.TypeService, + workload: &v1.Workload{ + Header: v1.Header{ + Type: v1.TypeService, }, - Service: &internalv1.Service{ - Base: internalv1.Base{ - Containers: map[string]internalv1.Container{ + Service: &v1.Service{ + Base: v1.Base{ + Containers: map[string]v1.Container{ "main": { Image: "nginx:latest", Dirs: map[string]string{ "/var/tmp-secret": "secret://other-sec-name", }, - Files: map[string]internalv1.FileSpec{ + Files: map[string]v1.FileSpec{ "/run/secret/password": { ContentFrom: "secret://sec-name/key?mode=0400", Mode: "0644", @@ -192,7 +191,7 @@ func TestGenerate(t *testing.T) { }, }, }, - Type: internalv1.Deployment, + Type: v1.Deployment, }, }, }, @@ -215,12 +214,12 @@ func TestGenerate(t *testing.T) { func TestToOrderedContainers(t *testing.T) { t.Run("toOrderedContainers should convert app containers to ordered containers", func(t *testing.T) { - appContainers := make(map[string]internalv1.Container) - appContainers["container1"] = internalv1.Container{ + appContainers := make(map[string]v1.Container) + appContainers["container1"] = v1.Container{ Image: "image1", Env: make(yaml.MapSlice, 0), } - appContainers["container2"] = internalv1.Container{ + appContainers["container2"] = v1.Container{ Image: "image2", Env: yaml.MapSlice{ { @@ -229,9 +228,9 @@ func TestToOrderedContainers(t *testing.T) { }, }, } - appContainers["container3"] = internalv1.Container{ + appContainers["container3"] = v1.Container{ Image: "image3", - Files: map[string]internalv1.FileSpec{ + Files: map[string]v1.FileSpec{ "/tmp/example1/file.txt": { Content: "some file contents", Mode: "0777", @@ -266,29 +265,29 @@ func TestToOrderedContainers(t *testing.T) { assert.Equal(t, wantedConfigMapData, actualConfigMaps[1].Data, "ConfigMap data mismatch") }) t.Run("toOrderedContainers should convert app containers with probe to ordered containers", func(t *testing.T) { - appContainers := map[string]internalv1.Container{ + appContainers := map[string]v1.Container{ "nginx": { Image: "nginx:v1", Resources: map[string]string{ "cpu": "2-4", "memory": "4Gi-8Gi", }, - LivenessProbe: &internalv1.Probe{ - ProbeHandler: &internalv1.ProbeHandler{ - TypeWrapper: internalv1.TypeWrapper{ + LivenessProbe: &v1.Probe{ + ProbeHandler: &v1.ProbeHandler{ + TypeWrapper: v1.TypeWrapper{ Type: "Exec", }, - ExecAction: &internalv1.ExecAction{ + ExecAction: &v1.ExecAction{ Command: []string{"/bin/sh", "-c", "echo live"}, }, }, }, - ReadinessProbe: &internalv1.Probe{ - ProbeHandler: &internalv1.ProbeHandler{ - TypeWrapper: internalv1.TypeWrapper{ + ReadinessProbe: &v1.Probe{ + ProbeHandler: &v1.ProbeHandler{ + TypeWrapper: v1.TypeWrapper{ Type: "Http", }, - HTTPGetAction: &internalv1.HTTPGetAction{ + HTTPGetAction: &v1.HTTPGetAction{ URL: "http://localhost:8080/readiness", Headers: map[string]string{ "header": "value", @@ -297,12 +296,12 @@ func TestToOrderedContainers(t *testing.T) { }, InitialDelaySeconds: 10, }, - StartupProbe: &internalv1.Probe{ - ProbeHandler: &internalv1.ProbeHandler{ - TypeWrapper: internalv1.TypeWrapper{ + StartupProbe: &v1.Probe{ + ProbeHandler: &v1.ProbeHandler{ + TypeWrapper: v1.TypeWrapper{ Type: "Tcp", }, - TCPSocketAction: &internalv1.TCPSocketAction{ + TCPSocketAction: &v1.TCPSocketAction{ URL: "10.0.0.1:8888", }, }, @@ -349,23 +348,23 @@ func TestToOrderedContainers(t *testing.T) { assert.Equal(t, "8888", actualContainers[0].StartupProbe.TCPSocket.Port.String(), "TCPSocket.Port mismatch") }) t.Run("toOrderedContainers should convert app containers with lifecycle to ordered containers", func(t *testing.T) { - appContainers := map[string]internalv1.Container{ + appContainers := map[string]v1.Container{ "nginx": { Image: "nginx:v1", - Lifecycle: &internalv1.Lifecycle{ - PreStop: &internalv1.LifecycleHandler{ - TypeWrapper: internalv1.TypeWrapper{ + Lifecycle: &v1.Lifecycle{ + PreStop: &v1.LifecycleHandler{ + TypeWrapper: v1.TypeWrapper{ Type: "Exec", }, - ExecAction: &internalv1.ExecAction{ + ExecAction: &v1.ExecAction{ Command: []string{"/bin/sh", "-c", "echo live"}, }, }, - PostStart: &internalv1.LifecycleHandler{ - TypeWrapper: internalv1.TypeWrapper{ + PostStart: &v1.LifecycleHandler{ + TypeWrapper: v1.TypeWrapper{ Type: "Http", }, - HTTPGetAction: &internalv1.HTTPGetAction{ + HTTPGetAction: &v1.HTTPGetAction{ URL: "http://localhost:8080/readiness", Headers: map[string]string{ "header": "value", @@ -403,15 +402,15 @@ func TestCompleteBaseWorkload(t *testing.T) { testcases := []struct { name string - base *internalv1.Base + base *v1.Base config v1.GenericConfig success bool - completedBase *internalv1.Base + completedBase *v1.Base }{ { name: "successfully complete base", - base: &internalv1.Base{ - Containers: map[string]internalv1.Container{ + base: &v1.Base{ + Containers: map[string]v1.Container{ "nginx": { Image: "nginx:v1", }, @@ -432,8 +431,8 @@ func TestCompleteBaseWorkload(t *testing.T) { "replicas": 4, }, success: true, - completedBase: &internalv1.Base{ - Containers: map[string]internalv1.Container{ + completedBase: &v1.Base{ + Containers: map[string]v1.Container{ "nginx": { Image: "nginx:v1", }, @@ -451,8 +450,8 @@ func TestCompleteBaseWorkload(t *testing.T) { }, { name: "use base replicas", - base: &internalv1.Base{ - Containers: map[string]internalv1.Container{ + base: &v1.Base{ + Containers: map[string]v1.Container{ "nginx": { Image: "nginx:v1", }, @@ -469,8 +468,8 @@ func TestCompleteBaseWorkload(t *testing.T) { "replicas": 4, }, success: true, - completedBase: &internalv1.Base{ - Containers: map[string]internalv1.Container{ + completedBase: &v1.Base{ + Containers: map[string]v1.Container{ "nginx": { Image: "nginx:v1", }, @@ -486,8 +485,8 @@ func TestCompleteBaseWorkload(t *testing.T) { }, { name: "use platform replicas", - base: &internalv1.Base{ - Containers: map[string]internalv1.Container{ + base: &v1.Base{ + Containers: map[string]v1.Container{ "nginx": { Image: "nginx:v1", }, @@ -503,8 +502,8 @@ func TestCompleteBaseWorkload(t *testing.T) { "replicas": 4, }, success: true, - completedBase: &internalv1.Base{ - Containers: map[string]internalv1.Container{ + completedBase: &v1.Base{ + Containers: map[string]v1.Container{ "nginx": { Image: "nginx:v1", }, @@ -520,8 +519,8 @@ func TestCompleteBaseWorkload(t *testing.T) { }, { name: "invalid replicas config", - base: &internalv1.Base{ - Containers: map[string]internalv1.Container{ + base: &v1.Base{ + Containers: map[string]v1.Container{ "nginx": { Image: "nginx:v1", }, @@ -535,8 +534,8 @@ func TestCompleteBaseWorkload(t *testing.T) { }, { name: "invalid labels config", - base: &internalv1.Base{ - Containers: map[string]internalv1.Container{ + base: &v1.Base{ + Containers: map[string]v1.Container{ "nginx": { Image: "nginx:v1", }, @@ -550,8 +549,8 @@ func TestCompleteBaseWorkload(t *testing.T) { }, { name: "invalid annotations config", - base: &internalv1.Base{ - Containers: map[string]internalv1.Container{ + base: &v1.Base{ + Containers: map[string]v1.Container{ "nginx": { Image: "nginx:v1", }, diff --git a/pkg/server/manager/stack/util.go b/pkg/server/manager/stack/util.go index c057e8d8..6a0a0f03 100644 --- a/pkg/server/manager/stack/util.go +++ b/pkg/server/manager/stack/util.go @@ -10,8 +10,7 @@ import ( "gorm.io/gorm" - apiv1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" - v1 "kusionstack.io/kusion/pkg/apis/internal.kusion.io/v1" + v1 "kusionstack.io/kusion/pkg/apis/api.kusion.io/v1" "kusionstack.io/kusion/pkg/backend" "kusionstack.io/kusion/pkg/backend/storages" "kusionstack.io/kusion/pkg/domain/constant" @@ -140,7 +139,11 @@ func (m *StackManager) getBackendFromWorkspaceName(ctx context.Context, workspac return remoteBackend, nil } -func (m *StackManager) previewHelper(ctx context.Context, id uint, workspaceName string) (*apiv1.Spec, *models.Changes, state.Storage, error) { +func (m *StackManager) previewHelper( + ctx context.Context, + id uint, + workspaceName string, +) (*v1.Spec, *models.Changes, state.Storage, error) { logger := util.GetLogger(ctx) logger.Info("Starting previewing stack in StackManager ...")