2019-04-06 13:44:04 +00:00
|
|
|
package kubernetes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
2021-11-26 02:34:48 +00:00
|
|
|
"os"
|
2019-04-06 13:44:04 +00:00
|
|
|
|
2021-11-26 02:34:48 +00:00
|
|
|
"github.com/woodpecker-ci/woodpecker/pipeline/backend/types"
|
2019-04-06 13:44:04 +00:00
|
|
|
)
|
|
|
|
|
2021-11-27 01:29:14 +00:00
|
|
|
type kube struct {
|
2019-04-06 13:44:04 +00:00
|
|
|
namespace string
|
|
|
|
endpoint string
|
|
|
|
token string
|
|
|
|
}
|
|
|
|
|
2021-11-27 01:29:14 +00:00
|
|
|
// make sure kube implements Engine
|
|
|
|
var _ types.Engine = &kube{}
|
|
|
|
|
2019-04-06 13:44:04 +00:00
|
|
|
// New returns a new Kubernetes Engine.
|
2021-11-26 02:34:48 +00:00
|
|
|
func New(namespace, endpoint, token string) types.Engine {
|
2021-11-27 01:29:14 +00:00
|
|
|
return &kube{
|
2019-04-06 13:44:04 +00:00
|
|
|
namespace: namespace,
|
|
|
|
endpoint: endpoint,
|
|
|
|
token: token,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-27 01:29:14 +00:00
|
|
|
func (e *kube) Name() string {
|
2021-11-26 02:34:48 +00:00
|
|
|
return "kubernetes"
|
|
|
|
}
|
|
|
|
|
2021-11-27 01:29:14 +00:00
|
|
|
func (e *kube) IsAvailable() bool {
|
2021-11-26 02:34:48 +00:00
|
|
|
host := os.Getenv("KUBERNETES_SERVICE_HOST")
|
|
|
|
return len(host) > 0
|
|
|
|
}
|
|
|
|
|
2021-11-27 01:29:14 +00:00
|
|
|
func (e *kube) Load() error {
|
2021-11-26 02:34:48 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-04-06 13:44:04 +00:00
|
|
|
// Setup the pipeline environment.
|
2021-11-27 01:29:14 +00:00
|
|
|
func (e *kube) Setup(context.Context, *types.Config) error {
|
2019-04-06 13:44:04 +00:00
|
|
|
// POST /api/v1/namespaces
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-11-27 01:29:14 +00:00
|
|
|
// Exec the pipeline step.
|
|
|
|
func (e *kube) Exec(context.Context, *types.Step) error {
|
2019-04-06 13:44:04 +00:00
|
|
|
// POST /api/v1/namespaces/{namespace}/pods
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for the pipeline step to complete and returns
|
|
|
|
// the completion results.
|
2021-11-27 01:29:14 +00:00
|
|
|
func (e *kube) Wait(context.Context, *types.Step) (*types.State, error) {
|
2019-04-06 13:44:04 +00:00
|
|
|
// GET /api/v1/watch/namespaces/{namespace}/pods
|
|
|
|
// GET /api/v1/watch/namespaces/{namespace}/pods/{name}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tail the pipeline step logs.
|
2021-11-27 01:29:14 +00:00
|
|
|
func (e *kube) Tail(context.Context, *types.Step) (io.ReadCloser, error) {
|
2019-04-06 13:44:04 +00:00
|
|
|
// GET /api/v1/namespaces/{namespace}/pods/{name}/log
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy the pipeline environment.
|
2021-11-27 01:29:14 +00:00
|
|
|
func (e *kube) Destroy(context.Context, *types.Config) error {
|
2019-04-06 13:44:04 +00:00
|
|
|
// DELETE /api/v1/namespaces/{name}
|
|
|
|
return nil
|
|
|
|
}
|