Files
poseidon/internal/kubernetes/api_querier.go
2024-09-18 10:43:38 +02:00

123 lines
3.8 KiB
Go

package kubernetes
import (
"context"
"errors"
nomadApi "github.com/hashicorp/nomad/api"
"io"
appv1 "k8s.io/api/apps/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
var (
ErrorNoAllocationFound = errors.New("no allocation found")
)
// apiQuerier provides access to the Nomad functionality.
type apiQuerier interface {
// init prepares an apiClient to be able to communicate to a provided Nomad API.
init(nomadConfig *rest.Config) (err error)
// LoadJobList loads the list of jobs from the Nomad API.
LoadJobList() (list []*appv1.DeploymentList, err error)
// JobScale returns the scale of the passed job.
JobScale(jobID string) (jobScale uint, err error)
// SetJobScale sets the scaling count of the passed job to Nomad.
SetJobScale(jobID string, count uint, reason string) (err error)
// DeleteJob deletes the Job with the given ID.
DeleteDeployment(name string) (err error)
// Execute runs a command in the passed job.
Execute(jobID string, ctx context.Context, command string, tty bool,
stdin io.Reader, stdout, stderr io.Writer) (int, error)
// listJobs loads all jobs with the specified prefix.
listDeployments(namespace string) (jobListStub []*appv1.DeploymentList, err error)
// job returns the job of the given jobID.
deployment(name string) (deployment appv1.Deployment, err error)
// listAllocations loads all allocations.
listAllocations() (allocationListStub []*nomadApi.AllocationListStub, err error)
// allocation returns the first allocation of the given job.
allocation(jobID string) (*nomadApi.Allocation, error)
// RegisterKubernetesDeployment registers a deployment with Kubernetes.
// It returns the deployment ID that can be used when listening to the Kubernetes event stream.
RegisterKubernetesDeployment(deployment appv1.Deployment) (string, error)
// EventStream returns a Nomad event stream filtered to return only allocation and evaluation events.
EventStream(ctx context.Context) (<-chan *nomadApi.Events, error)
}
// nomadAPIClient implements the nomadApiQuerier interface and provides access to a real Nomad API.
type kubernetesAPIClient struct {
client *kubernetes.Clientset
namespace string
}
func (k kubernetesAPIClient) init(nomadConfig *rest.Config) (err error) {
//TODO implement me
panic("implement me")
}
func (k kubernetesAPIClient) LoadJobList() (list []*appv1.DeploymentList, err error) {
//TODO implement me
panic("implement me")
}
func (k kubernetesAPIClient) JobScale(jobID string) (jobScale uint, err error) {
//TODO implement me
panic("implement me")
}
func (k kubernetesAPIClient) SetJobScale(jobID string, count uint, reason string) (err error) {
//TODO implement me
panic("implement me")
}
func (k kubernetesAPIClient) DeleteDeployment(name string) (err error) {
//TODO implement me
panic("implement me")
}
func (k kubernetesAPIClient) Execute(jobID string, ctx context.Context, command string, tty bool, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
//TODO implement me
panic("implement me")
}
func (k kubernetesAPIClient) listDeployments(namespace string) (jobListStub []*appv1.DeploymentList, err error) {
//TODO implement me
panic("implement me")
}
func (k kubernetesAPIClient) deployment(name string) (deployment appv1.Deployment, err error) {
//TODO implement me
panic("implement me")
}
func (k kubernetesAPIClient) listAllocations() (allocationListStub []*nomadApi.AllocationListStub, err error) {
//TODO implement me
panic("implement me")
}
func (k kubernetesAPIClient) allocation(jobID string) (*nomadApi.Allocation, error) {
//TODO implement me
panic("implement me")
}
func (k kubernetesAPIClient) RegisterKubernetesDeployment(deployment appv1.Deployment) (string, error) {
//TODO implement me
panic("implement me")
}
func (k kubernetesAPIClient) EventStream(ctx context.Context) (<-chan *nomadApi.Events, error) {
//TODO implement me
panic("implement me")
}