Skip to content
This repository has been archived by the owner on Jun 23, 2020. It is now read-only.

pulls in DRONE_RUNNER_ANNOTATONS and puts it on the job spec #61

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions engine/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/drone/drone-runtime/engine"
"github.com/drone/drone-runtime/engine/docker/auth"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/informers"
Expand All @@ -25,13 +25,14 @@ import (
)

type kubeEngine struct {
client *kubernetes.Clientset
node string
client *kubernetes.Clientset
node string
annotations map[string]string
}

// NewFile returns a new Kubernetes engine from a
// Kubernetes configuration file (~/.kube/config).
func NewFile(url, path, node string) (engine.Engine, error) {
func NewFile(url, path, node string, annotations map[string]string) (engine.Engine, error) {
config, err := clientcmd.BuildConfigFromFlags(url, path)
if err != nil {
return nil, err
Expand All @@ -40,7 +41,7 @@ func NewFile(url, path, node string) (engine.Engine, error) {
if err != nil {
return nil, err
}
return &kubeEngine{client: client, node: node}, nil
return &kubeEngine{client: client, node: node, annotations: annotations}, nil
}

func (e *kubeEngine) Setup(ctx context.Context, spec *engine.Spec) error {
Expand Down Expand Up @@ -133,6 +134,10 @@ func (e *kubeEngine) Start(ctx context.Context, spec *engine.Spec, step *engine.
}
}

if len(e.annotations) != 0 {
pod.ObjectMeta.Annotations = e.annotations
}

if e.node != "" {
pod.Spec.Affinity = &v1.Affinity{
NodeAffinity: &v1.NodeAffinity{
Expand Down
13 changes: 8 additions & 5 deletions engine/kube/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ package kube
import (
"path"
"path/filepath"
"strings"
"strconv"
"strings"

"github.com/drone/drone-runtime/engine"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
Expand All @@ -22,6 +22,7 @@ import (

// helper function converts environment variable
// string data to kubernetes variables.

func toEnv(spec *engine.Spec, step *engine.Step) []v1.EnvVar {
var to []v1.EnvVar
for k, v := range step.Envs {
Expand Down Expand Up @@ -236,6 +237,7 @@ func toResources(step *engine.Step) v1.ResourceRequirements {
// helper function returns a kubernetes pod for the
// given step and specification.
func toPod(spec *engine.Spec, step *engine.Step) *v1.Pod {

var volumes []v1.Volume
volumes = append(volumes, toVolumes(spec, step)...)
volumes = append(volumes, toConfigVolumes(spec, step)...)
Expand All @@ -253,9 +255,10 @@ func toPod(spec *engine.Spec, step *engine.Step) *v1.Pod {

return &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: step.Metadata.UID,
Namespace: step.Metadata.Namespace,
Labels: step.Metadata.Labels,
Name: step.Metadata.UID,
Namespace: step.Metadata.Namespace,
Labels: step.Metadata.Labels,
Annotations: step.Annotations,
},
Spec: v1.PodSpec{
AutomountServiceAccountToken: boolptr(false),
Expand Down
1 change: 1 addition & 0 deletions engine/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type (
// Step defines a pipeline step.
Step struct {
Metadata Metadata `json:"metadata,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Detach bool `json:"detach,omitempty"`
DependsOn []string `json:"depends_on,omitempty"`
Devices []*VolumeDevice `json:"devices,omitempty"`
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ func main() {
log.Fatalln(err)
}
} else {
engine, err = kube.NewFile(*u, *k, *n)
// send Empty annotatoins to NewFile
a := map[string]string{}
engine, err = kube.NewFile(*u, *k, *n, a)
if err != nil {
log.Fatalln(err)
}
Expand Down