openapi

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2019 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package openapi Wayne OpenAPI Document

wayne 开放 API (以下简称 openapi)是一组便于开发者调试、第三方工具开发和 CI/CD 的开放数据接口。 openapi 虽然格式上满足 Restful,但是并不是单一接口只针对特定资源的操作,在大部分时候单一接口会操作一组资源; 同时,虽然 openapi 下只允许通过 GET 请求访问,但是并不意味着 GET 操作代表着 Restful 中对 GET 的用法定义; openapi 的路径格式:/openapi/v1/gateway/action/:action,:action 代表特定操作,例如: get_vip_info、upgrade_deployment。

openapi 所操作的 action 必须搭配具有该 action 权限的 APIKey 使用(作为一个命名为 apikey 的 GET 请求参数), 而对应的 apikey 需要具备 action 对应的权限(例如:action 对应 get_pod_info 的时候,apikey 需要具备 OPENAPI_GET_POD_INFO 权限), 同时,受限于某些action的使用场景,可能强制要求附加的 APIKey 的使用范围,目前APIKey的适用范围包括三种,App 级别、Namespace 级别 以及 全局级别。 Terms Of Service:

Schemes: https
Host: localhost
BasePath: /openapi/v1/gateway/action
Version: 1.6.1

Consumes:
- application/json

Produces:
- application/json

Security:
- api_key:

SecurityDefinitions:
api_key:
     type: apiKey
     name: apikey
     in: query

swagger:meta

Index

Constants

View Source
const (
	GetPodInfoAction          = "GET_POD_INFO"
	GetPodInfoFromIPAction    = "GET_POD_INFO_FROM_IP"
	GetResourceInfoAction     = "GET_RESOURCE_INFO"
	GetDeploymentStatusAction = "GET_DEPLOYMENT_STATUS"
	UpgradeDeploymentAction   = "UPGRADE_DEPLOYMENT"
	ScaleDeploymentAction     = "SCALE_DEPLOYMENT"
	RestartDeploymentAction   = "RESTART_DEPLOYMENT"
	GetPodListAction          = "GET_POD_LIST"
	PermissionPrefix          = "OPENAPI_"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DeploymentInfo

type DeploymentInfo struct {
	Deployment         *models.Deployment
	DeploymentTemplete *models.DeploymentTemplate
	DeploymentObject   *v1beta1.Deployment
	Cluster            *models.Cluster
	Namespace          *models.Namespace
}

type DeploymentStatus

type DeploymentStatus struct {
	// required: true
	Pods []response.Pod `json:"pods"`
	// required: true
	Deployment response.Deployment `json:"deployment"`
	// required: true
	Healthz bool `json:"healthz"`
}

swagger:model deploymentstatus

type DeploymentStatusParam

type DeploymentStatusParam struct {
	// in: query
	// Required: true
	Deployment string `json:"deployment"`
	// Required: true
	Namespace string `json:"namespace"`
	// 和升级部署存在差别,不允许同时填写多个 cluster
	// Required: true
	Cluster string `json:"cluster"`
}

swagger:parameters DeploymentStatusParam

type OpenAPIController

type OpenAPIController struct {
	base.APIKeyController
}

func (*OpenAPIController) CheckDeploymentPermission

func (c *OpenAPIController) CheckDeploymentPermission(deployment string) bool

func (*OpenAPIController) CheckNamespacePermission

func (c *OpenAPIController) CheckNamespacePermission(namespace string) bool

func (*OpenAPIController) CheckoutRoutePermission

func (c *OpenAPIController) CheckoutRoutePermission(action string) bool

func (*OpenAPIController) GetDeploymentStatus

func (c *OpenAPIController) GetDeploymentStatus()

swagger:route GET /get_deployment_status deploy DeploymentStatusParam

该接口用于返回特定部署的状态信息

重点关注 kubernetes 集群内状态而非描述信息,当然也可以只关注 healthz 字段。 该接口可以使用所有种类的 apikey

Responses:
  200: respdeploymentstatus
  400: responseState
  401: responseState
  500: responseState

@router /get_deployment_status [get]

func (*OpenAPIController) GetPodInfo

func (c *OpenAPIController) GetPodInfo()

swagger:route GET /get_pod_info pod PodInfoParam

用于获取线上所有 pod 中包含请求条件中 labelSelector 指定的特定 label 的 pod

返回 每个 pod 的 pod IP 和 所有 label 列表。 需要绑定全局 apikey 使用。该接口的权限控制为只能使用全局 apikey 的原因是查询条件为 labelSelector ,是对所有 app 的 条件过滤。

Responses:
  200: resppodlist
  401: responseState
  500: responseState

@router /get_pod_info [get]

func (*OpenAPIController) GetPodInfoFromIP added in v1.2.0

func (c *OpenAPIController) GetPodInfoFromIP()

swagger:route GET /get_pod_info_from_ip pod PodInfoFromIPParam

用于通过线上 kubernetes Pod IP 反查对应 Pod 信息的接口

返回 每个 pod 的 pod IP 和 所有 label 列表。 需要绑定全局 apikey 使用。该接口的权限控制为只能使用全局 apikey 的原因是查询条件为 IP ,是对所有 app 的 条件过滤。

Responses:
  200: resppodlist
  401: responseState
  500: responseState

@router /get_pod_info_from_ip [get]

func (*OpenAPIController) GetPodList added in v1.6.0

func (c *OpenAPIController) GetPodList()

swagger:route GET /get_pod_list pod PodListParam

用于根据资源类型获取所有机房Pod列表

返回 Pod 信息 需要绑定全局 apikey 使用。

Responses:
  200: respPodInfoList
  401: responseState
  500: responseState

@router /get_pod_list [get]

func (*OpenAPIController) GetResourceInfo

func (c *OpenAPIController) GetResourceInfo()

swagger:route GET /get_resource_info resource ResourceInfoParam

通过给定的资源类型和资源名称反查出资源所属的 app 和 用户信息

因为查询范围是对所有的服务进行的,因此需要绑定 全局 apikey 使用。

Responses:
  200: respresourceinfo
  400: responseState
  500: responseState

@router /get_resource_info [get]

func (*OpenAPIController) Prepare

func (c *OpenAPIController) Prepare()

func (*OpenAPIController) RestartDeployment added in v1.1.0

func (c *OpenAPIController) RestartDeployment()

swagger:route GET /restart_deployment deploy RestartDeploymentParam

用于用户调用以实现强制重启部署

该接口只能使用 app 级别的 apikey,这样做的目的主要是防止 apikey 的滥用

Responses:
  200: responseSuccess
  400: responseState
  401: responseState
  500: responseState

@router /restart_deployment [get]

func (*OpenAPIController) ScaleDeployment

func (c *OpenAPIController) ScaleDeployment()

swagger:route GET /scale_deployment deploy ScaleDeploymentParam

用于 CI/CD 中的部署水平扩容/缩容

副本数量范围为0-32 该接口只能使用 app 级别的 apikey,这样做的目的主要是防止 apikey 的滥用

Responses:
  200: responseSuccess
  400: responseState
  401: responseState
  500: responseState

@router /scale_deployment [get]

func (*OpenAPIController) UpgradeDeployment

func (c *OpenAPIController) UpgradeDeployment()

swagger:route GET /upgrade_deployment deploy UpgradeDeploymentParam

用于 CI/CD 中的集成升级部署

该接口只能使用 app 级别的 apikey,这样做的目的主要是防止 apikey 的滥用。 目前用户可以选择两种用法,第一种是默认的,会根据请求的 images 和 environments 对特定部署线上模板进行修改并创建新模板,然后使用新模板进行升级; 需要说明的是,environments 列表会对 deployment 内所有容器中包含指定环境变量 key 的环境变量进行更新,如不包含,则不更新。 第二种是通过指定 publish=false 来关掉直接上线,这种条件下会根据 images 和 environments 字段创建新的模板,并返回新模板id,用户可以选择去平台上手动上线或者通过本接口指定template_id参数上线。 cluster 字段可以选择单个机房也可以选择多个机房,对于创建模板并上线的用法,会根据指定的机房之前的模板进行分类(如果机房 a 和机房 b 使用同一个模板,那么调用以后仍然共用一个新模板) 而对于指定 template_id 来上线的形式,则会忽略掉所有检查,直接使用特定模板上线到所有机房。

Responses:
  200: responseSuccess
  400: responseState
  401: responseState
  500: responseState

@router /upgrade_deployment [get]

type PodInfoFromIPParam added in v1.2.0

type PodInfoFromIPParam struct {
	// in: query
	// Pod IP 列表,使用逗号分隔
	// Required: true
	IPS string `json:"ips"`

	// Required: true
	Cluster string `json:"cluster"`
	// contains filtered or unexported fields
}

swagger:parameters PodInfoFromIPParam

type PodInfoParam

type PodInfoParam struct {
	// in: query
	// Pod Label Key,只允许填写一个
	// Required: true
	LabelSelector string `json:"labelSelector"`
	// Required: true
	Cluster string `json:"cluster"`
}

swagger:parameters PodInfoParam

type PodListParam added in v1.6.0

type PodListParam struct {
	// Wayne 的 namespace 名称,必须与 Name 同时存在或者不存在
	// in: query
	// Required: false
	Namespace string `json:"namespace"`
	// 资源名称,必须与 Namespace 同时存在或者不存在
	// in: query
	// Required: false
	Name string `json:"name"`
	// 资源类型:daemonsets,deployments,cronjobs,statefulsets
	// in: query
	// Required: true
	Type api.ResourceName `json:"type"`
}

swagger:parameters PodListParam

type RestartDeploymentParam added in v1.1.0

type RestartDeploymentParam struct {
	// in: query
	// Required: true
	Deployment string `json:"deployment"`
	// Required: true
	Namespace string `json:"namespace"`
	// 和升级部署存在差别,不允许同时填写多个 cluster
	// Required: true
	Cluster string `json:"cluster"`
}

swagger:parameters RestartDeploymentParam

type ScaleDeploymentParam

type ScaleDeploymentParam struct {
	// in: query
	// Required: true
	Deployment string `json:"deployment"`
	// Required: true
	Namespace string `json:"namespace"`
	// 和升级部署存在差别,不允许同时填写多个 cluster
	// Required: true
	Cluster string `json:"cluster"`
	// 期望调度到的副本数量,范围:(0,32]
	// Required: true
	Replicas int `json:"replicas"`
}

swagger:parameters ScaleDeploymentParam

type UpgradeDeploymentParam

type UpgradeDeploymentParam struct {
	// in: query
	// Required: true
	Deployment string `json:"deployment"`
	// Required: true
	Namespace string `json:"namespace"`
	// 支持同时填写多个 Cluster,只需要在 cluster 之间使用英文半角的逗号分隔即可
	// Required: true
	Cluster string `json:"cluster"`

	// Required: false
	TemplateId int `json:"template_id"`
	// 该字段为 true 的时候,会自动使用新生成的配置模板上线,否则会只创建对应的模板,并且将模板 ID 返回(用于敏感的需要手动操作的上线环境)
	// Required: false
	Publish bool `json:"publish"`
	// 升级的描述
	// Required: false
	Description string `json:"description"`
	// 该字段为扁平化为字符串的 key-value 字典,填写格式为 容器名1=镜像名1,容器名2=镜像名2 (即:多个容器之间使用英文半角的逗号分隔)
	// Required: false
	Images string `json:"images"`

	// 该字段为扁平化为字符串的 key-value 字典,填写格式为 环境变量1=值1,环境变量2=值2 (即:多个环境变量之间使用英文半角的逗号分隔)
	// Required: false
	Environments string `json:"environments"`
	// contains filtered or unexported fields
}

swagger:parameters UpgradeDeploymentParam

Jump to

Keyboard shortcuts

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