k8sclient

package
v0.0.0-...-69c2794 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Image Builder Environment variables
	EnvGitRepo        = "GIT_REPO"
	EnvGitBranch      = "GIT_BRANCH"
	EnvImageName      = "IMAGE_NAME"
	EnvImageTag       = "IMAGE_TAG"
	EnvDockerBaseDir  = "DOCKER_BASE_DIR"
	EnvDockerFilePath = "DOCKER_FILE_PATH"
	EnvDockerRegistry = "DOCKER_REGISTRY"
	EnvDockerUser     = "DOCKER_REGISTRY_USER"
	EnvDockerPassword = "DOCKER_REGISTRY_PASSWORD"
)
View Source
const (
	// AppLabel は ns やリソースに付与するラベルのキー。
	AppLabel = "app"
	// CreatedByLabel は ns やリソースに付与するラベルのキー。
	// このラベルが付与されたリソースは gantry によって作成されたものとみなす
	CreatedByLabel = "created"
	// RepositoryLabel はリソースに付与するラベルのキー。
	// このラベルが付与されたリソースはどのリポジトリに関連するかを示す
	RepositoryLabel = "repository"
	// PrIDLabel はリソースに付与するラベルのキー。
	// このラベルが付与されたリソースはどの PR に関連するかを示す
	PullRequestID = "pr-id"
	// BaseBranchLabel はリソースに付与するラベルのキー。
	// このラベルが付与されたリソースはどのブランチに関連するかを示す
	BaseBranchLabel = "base-branch"
	// EnvirionmentLabel はリソースに付与するラベルのキー。
	// このラベルが付与されたリソースはどの環境に関連するかを示す
	// 基本Botから生成されるデプロイにはpreviewが付与される
	// ex: staging , production , preview
	EnvirionmentLabel = "envirionment"
)

gantryで扱うラベルの定義

View Source
const (
	// AppIdentifier は gantry が扱うリソースの識別子
	AppIdentifier = "gantry"

	// EnvProduction は本番環境を示す
	EnvProduction = "production"
	// EnvStaging はステージング環境を示す
	EnvStaging = "staging"
	// EnvPreview はプレビュー環境を示す
	EnvPreview = "preview"
)
View Source
const (
	// DefaultBackoffLimit はジョブのバックオフリミットのデフォルト値 .
	DefaultBackoffLimit = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BuilderParams

type BuilderParams struct {
	Namespace string
	Branch    string

	BuilderParam ImageBuilderParams
}

type CreateDeploymentParams

type CreateDeploymentParams struct {
	Namespace string
	AppName   string
	Image     string
	Replicas  int32
	Config    []*pbv1.Config
}

type CreateServiceNodePortParams

type CreateServiceNodePortParams struct {
	Namespace   string
	ServiceName string
	TargetPort  []int32
}

type GetDeploymentParams

type GetDeploymentParams struct {
	Namespace     string
	Repository    string
	PullRequestID string
	Branch        string
}

type ImageBuilderParams

type ImageBuilderParams struct {
	Repository     string
	GitRepo        string
	GitBranch      string
	ImageName      string
	ImageTag       string
	DockerBaseDir  string
	DockerFilePath string
	Token          string
}

type K8SClient

type K8SClient interface {
	// namespace
	CreateNamespace(ctx context.Context, name string, opts ...Option) (*corev1.Namespace, error)
	ListNamespaces(ctx context.Context, opts ...Option) (*corev1.NamespaceList, error)
	DeleteNamespace(ctx context.Context, name string) error

	// deployment
	CreateDeployment(ctx context.Context, in CreateDeploymentParams, opts ...Option) (*appsv1.Deployment, error)
	GetDeployment(ctx context.Context, param GetDeploymentParams) (*appsv1.Deployment, error)
	ListDeployments(ctx context.Context, namespace string, opts ...Option) (*appsv1.DeploymentList, error)
	UpdateDeployment(ctx context.Context, dep *appsv1.Deployment, in UpdateDeploymentParams, opts ...Option) (*appsv1.Deployment, error)
	DeleteDeployment(ctx context.Context, namespace string, opts ...Option) error

	// service
	CreateLoadBalancerService(ctx context.Context, param CreateServiceNodePortParams, opts ...Option) (*corev1.Service, error)
	DeleteService(ctx context.Context, namespace string, opts ...Option) error

	// replica set
	GetReplicaSet(ctx context.Context, namespace string, prefix string) (*appsv1.ReplicaSet, error)

	// pod
	GetPods(ctx context.Context, namespace, prefix string) ([]*corev1.Pod, error)
	CreatePod(ctx context.Context, pod *corev1.Pod, opts metav1.CreateOptions) (*corev1.Pod, error)
	UpdatePod(ctx context.Context, pod *corev1.Pod, opts metav1.UpdateOptions) (*corev1.Pod, error)
	DeletePod(ctx context.Context, namespace, name string, opts metav1.DeleteOptions) error
	GetPodUsage(ctx context.Context, namespace, podName string) (*protoV1.Pod, error)

	// log
	GetLogs(namespace string, podName string, option corev1.PodLogOptions) *restclient.Request

	// builder
	Builder(ctx context.Context, param BuilderParams, opts ...Option) (string, error)

	// config map
	CreateConfigMap(ctx context.Context, configMap corev1.ConfigMap, opts metav1.CreateOptions) error
	UpdateConfigMap(ctx context.Context, configMap corev1.ConfigMap, opts metav1.UpdateOptions) error
	DeleteConfigMap(ctx context.Context, namespace string, name string, opts metav1.DeleteOptions) error
}

func New

func New(client *kubernetes.Clientset, metrics *metrics.Clientset) K8SClient

type Option

type Option func(*option)

func WithAppLabel

func WithAppLabel(appName string) Option

func WithBaseBranchLabel

func WithBaseBranchLabel(baseBranch string) Option

func WithCreatedByLabel

func WithCreatedByLabel(name string) Option

func WithEnvirionmentLabel

func WithEnvirionmentLabel(envirionment string) Option

func WithImagePullPolicy

func WithImagePullPolicy(image, policy string) Option

func WithLabelSelector

func WithLabelSelector(labelSelector map[string]string) Option

func WithPrIDLabel

func WithPrIDLabel(prID string) Option

func WithReplica

func WithReplica(replica int32) Option

func WithRepositoryLabel

func WithRepositoryLabel(repository string) Option

type UpdateDeploymentParams

type UpdateDeploymentParams struct {
	Namespace     string
	Repository    string
	PullRequestID string
	Branch        string
	AppName       string
	Image         *string
	Replicas      *int32
	Config        []*pbv1.Config
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL