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 4 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
11 changes: 2 additions & 9 deletions engine/kube/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"strings"

"github.com/drone/drone-runtime/engine"
"github.com/drone/drone/cmd/drone-controller/config"
"github.com/sirupsen/logrus"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
Expand All @@ -24,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 @@ -238,12 +237,6 @@ 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 {
config, err := config.Environ()

if err != nil {
logrus.WithError(err).Fatalln("invalid configuration")

}

var volumes []v1.Volume
volumes = append(volumes, toVolumes(spec, step)...)
Expand All @@ -265,7 +258,7 @@ func toPod(spec *engine.Spec, step *engine.Step) *v1.Pod {
Name: step.Metadata.UID,
Namespace: step.Metadata.Namespace,
Labels: step.Metadata.Labels,
Annotations: config.Runner.Annotations,
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"`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's a double quote missing here.

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