<commit_before>package kubernetes

import (
	"errors"
	"fmt"
	"io"
	"strings"

	"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
	"gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors"

	"k8s.io/kubernetes/pkg/api"
	client "k8s.io/kubernetes/pkg/client/unversioned"
)

var (
	kubeClient *client.Client
)

type kubernetesOptions struct {
	Image    string   `json:"image"`
	Services []string `json:"services"`
	// TODO: Support a whitelist of images that can be privileged?
	Privileged bool `json:"privileged"`
}

type executor struct {
	executors.AbstractExecutor

	pod     *api.Pod
	options *kubernetesOptions
}

func (s *executor) Prepare(globalConfig *common.Config, config *common.RunnerConfig, build *common.Build) error {
	err := s.AbstractExecutor.Prepare(globalConfig, config, build)
	if err != nil {
		return err
	}

	fmt.Printf("Got runner config: %s\n", config)
	fmt.Printf("Got build: %s\n", build)
	var proxyURL string
	var allowPrivileged bool
	if config.Kubernetes != nil {
		proxyURL = config.Kubernetes.ProxyURL
		allowPrivileged = config.Kubernetes.AllowPrivileged
	}

	if kubeClient == nil {
		kubeClient, err = getKubeClient(proxyURL)
		if err != nil {
			return err
		}
	}

	if s.BuildScript.PassFile {
		return errors.New("Kubernetes doesn't support shells that require script file")
	}

	err = build.Options.Decode(&s.options)
	if err != nil {
		return err
	}

	if !allowPrivileged && s.options.Privileged {
		return errors.New("Attempting to run privileged container but runner config does not allow it")
	}

	s.Println("Using Kubernetes executor with image", s.options.Image, "...")

	return nil
}

func (s *executor) Cleanup() {
	if s.pod != nil {
		err := kubeClient.Pods(s.pod.Namespace).Delete(s.pod.Name, nil)

		if err != nil {
			s.Errorln("Error cleaning up pod: %s", err.Error())
		}
	}
	s.AbstractExecutor.Cleanup()
}

func (s *executor) Start() error {
	s.Debugln("Starting Kubernetes command...")

	var err error
	s.pod, err = kubeClient.Pods(s.Config.Kubernetes.Namespace).Create(&api.Pod{
		ObjectMeta: api.ObjectMeta{
			GenerateName: s.Build.ProjectUniqueName(),
			Namespace:    s.Config.Kubernetes.Namespace,<commit_msg>Update for new interface def.<commit_after>package kubernetes

import (
	"errors"
	"fmt"
	"io"
	"strings"

	"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
	"gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors"

	"k8s.io/kubernetes/pkg/api"
	client "k8s.io/kubernetes/pkg/client/unversioned"
)

var (
	kubeClient *client.Client
)

type kubernetesOptions struct {
	Image    string   `json:"image"`
	Services []string `json:"services"`
	// TODO: Support a whitelist of images that can be privileged?
	Privileged bool `json:"privileged"`
}

type executor struct {
	executors.AbstractExecutor

	pod     *api.Pod
	options *kubernetesOptions
}

func (s *executor) Prepare(globalConfig *common.Config, config *common.RunnerConfig, build *common.Build) error {
	err := s.AbstractExecutor.Prepare(globalConfig, config, build)
	if err != nil {
		return err
	}

	fmt.Printf("Got runner config: %s\n", config)
	fmt.Printf("Got build: %s\n", build)
	var proxyURL string
	var allowPrivileged bool
	if config.Kubernetes != nil {
		proxyURL = config.Kubernetes.ProxyURL
		allowPrivileged = config.Kubernetes.AllowPrivileged
	}

	if kubeClient == nil {
		kubeClient, err = getKubeClient(proxyURL)
		if err != nil {
			return err
		}
	}

	if s.BuildScript.PassFile {
		return errors.New("Kubernetes doesn't support shells that require script file")
	}

	err = build.Options.Decode(&s.options)
	if err != nil {
		return err
	}

	if !allowPrivileged && s.options.Privileged {
		return errors.New("Attempting to run privileged container but runner config does not allow it")
	}

	s.Println("Using Kubernetes executor with image", s.options.Image, "...")

	return nil
}

func (s *executor) Cleanup() {
	if s.pod != nil {
		err := kubeClient.Pods(s.pod.Namespace).Delete(s.pod.Name, nil)

		if err != nil {
			s.Errorln("Error cleaning up pod: %s", err.Error())
		}
	}
	s.AbstractExecutor.Cleanup()
}

func (s *executor) Run(cmd common.ExecutorCommand) error {
	s.Debugln("Starting Kubernetes command...")

	var err error
	s.pod, err = kubeClient.Pods(s.Config.Kubernetes.Namespace).Create(&api.Pod{
		ObjectMeta: api.ObjectMeta{
			GenerateName: s.Build.ProjectUniqueName(),
			Namespace:    s.Config.Kubernetes.Namespace,
{'fraction_non_alphanumeric': 0.12836911831886708, 'fraction_numerical': 0.0009136592051164915, 'mean_word_length': 4.115654205607477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6877671', 'n_tokens_mistral': 1591, 'n_tokens_neox': 1500, 'n_words': 362}