v2.01 move agent spec to separate file
This commit is contained in:
Родитель
75fbef973b
Коммит
5bea08f5dd
|
@ -15,5 +15,7 @@ ADD . /app/
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
RUN go build -o main .
|
RUN go build -o main .
|
||||||
|
|
||||||
|
COPY agentpods/* agentpods/
|
||||||
|
|
||||||
EXPOSE 8082
|
EXPOSE 8082
|
||||||
CMD ["/app/main"]
|
CMD ["/app/main"]
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
name: vsts-agent-dind
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: vsts-agent
|
||||||
|
image: microsoft/vsts-agent:ubuntu-16.04-docker-18.06.1-ce-standard
|
||||||
|
env:
|
||||||
|
- name: VSTS_ACCOUNT
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: vsts
|
||||||
|
key: VSTS_ACCOUNT
|
||||||
|
- name: VSTS_TOKEN
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: vsts
|
||||||
|
key: VSTS_TOKEN
|
||||||
|
- name: VSTS_POOL
|
||||||
|
value: divman
|
||||||
|
- name: DOCKER_HOST
|
||||||
|
value: tcp://localhost:2375
|
||||||
|
- name: dind-daemon
|
||||||
|
image: docker:18.09.6-dind
|
||||||
|
securityContext:
|
||||||
|
privileged: true
|
||||||
|
volumeMounts:
|
||||||
|
- name: agent-pv-storage
|
||||||
|
mountPath: /var/lib/docker
|
||||||
|
volumes:
|
||||||
|
- name: agent-pv-storage
|
||||||
|
emptyDir: {}
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"github.com/ghodss/yaml"
|
"github.com/ghodss/yaml"
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
@ -10,62 +11,19 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreatePod() string {
|
func CreatePod() string {
|
||||||
config, err := rest.InClusterConfig()
|
cs, err := getInClusterClientSet()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error()
|
return err.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
clientset, err := kubernetes.NewForConfig(config)
|
var podYaml = getDefaultAgentSpecification()
|
||||||
if err != nil {
|
|
||||||
return err.Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
// If pod is to be created in a different namespace
|
|
||||||
// then secrets need to be created in the same namespace, i.e. VSTS_TOKEN and VSTS_ACCOUNT
|
|
||||||
// kubectl create secret generic vsts --from-literal=VSTS_TOKEN=<token> --from-literal=VSTS_ACCOUNT=mseng
|
|
||||||
var podYaml = `
|
|
||||||
apiVersion: v1
|
|
||||||
kind: Pod
|
|
||||||
metadata:
|
|
||||||
name: vsts-agent-dind
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- name: vsts-agent
|
|
||||||
image: microsoft/vsts-agent:ubuntu-16.04-docker-18.06.1-ce-standard
|
|
||||||
env:
|
|
||||||
- name: VSTS_ACCOUNT
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: vsts
|
|
||||||
key: VSTS_ACCOUNT
|
|
||||||
- name: VSTS_TOKEN
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: vsts
|
|
||||||
key: VSTS_TOKEN
|
|
||||||
- name: VSTS_POOL
|
|
||||||
value: divman
|
|
||||||
- name: DOCKER_HOST
|
|
||||||
value: tcp://localhost:2375
|
|
||||||
- name: dind-daemon
|
|
||||||
image: docker:18.09.6-dind
|
|
||||||
securityContext:
|
|
||||||
privileged: true
|
|
||||||
volumeMounts:
|
|
||||||
- name: agent-pv-storage
|
|
||||||
mountPath: /var/lib/docker
|
|
||||||
volumes:
|
|
||||||
- name: agent-pv-storage
|
|
||||||
emptyDir: {}
|
|
||||||
`
|
|
||||||
|
|
||||||
var p1 v1.Pod
|
var p1 v1.Pod
|
||||||
err1 := yaml.Unmarshal([]byte(podYaml), &p1)
|
err1 := yaml.Unmarshal([]byte(podYaml), &p1)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
return "unmarshal error: " + err1.Error()
|
return "unmarshal error: " + err1.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
podClient := clientset.CoreV1().Pods("azuredevops")
|
podClient := cs.CoreV1().Pods("azuredevops")
|
||||||
pod, err2 := podClient.Create(&p1)
|
pod, err2 := podClient.Create(&p1)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
return "podclient create error: " + err2.Error()
|
return "podclient create error: " + err2.Error()
|
||||||
|
@ -75,21 +33,44 @@ func CreatePod() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeletePod(podname string) string {
|
func DeletePod(podname string) string {
|
||||||
config, err := rest.InClusterConfig()
|
cs, err := getInClusterClientSet()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error()
|
return err.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
clientset, err := kubernetes.NewForConfig(config)
|
podClient := cs.CoreV1().Pods("azuredevops")
|
||||||
if err != nil {
|
|
||||||
return err.Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
podClient := clientset.CoreV1().Pods("azuredevops")
|
|
||||||
err2 := podClient.Delete(podname, &metav1.DeleteOptions{})
|
err2 := podClient.Delete(podname, &metav1.DeleteOptions{})
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
return "podclient delete error: " + err2.Error()
|
return "podclient delete error: " + err2.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Deleted " + podname
|
return "Deleted " + podname
|
||||||
|
}
|
||||||
|
|
||||||
|
func getInClusterClientSet() (*kubernetes.Clientset, error) {
|
||||||
|
config, err := rest.InClusterConfig()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
clientset, err := kubernetes.NewForConfig(config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return clientset, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDefaultAgentSpecification() string {
|
||||||
|
// If pod is to be created in a different namespace
|
||||||
|
// then secrets need to be created in the same namespace, i.e. VSTS_TOKEN and VSTS_ACCOUNT
|
||||||
|
// kubectl create secret generic vsts --from-literal=VSTS_TOKEN=<token> --from-literal=VSTS_ACCOUNT=mseng
|
||||||
|
dat, err := ioutil.ReadFile("agentpods/agent-dind.yaml")
|
||||||
|
if err != nil {
|
||||||
|
return err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
var podYaml = string(dat)
|
||||||
|
return podYaml
|
||||||
}
|
}
|
|
@ -54,7 +54,7 @@ spec:
|
||||||
spec:
|
spec:
|
||||||
serviceAccountName: pipelineprovider
|
serviceAccountName: pipelineprovider
|
||||||
containers:
|
containers:
|
||||||
- image: divyanshm/goserver:v2.0
|
- image: divyanshm/goserver:v2.01
|
||||||
name: goserver
|
name: goserver
|
||||||
command: ["/app/main"]
|
command: ["/app/main"]
|
||||||
ports:
|
ports:
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
#!/bin/sh -e
|
|
||||||
|
|
||||||
#
|
|
||||||
# This script is inspired by coreos/etcd.
|
|
||||||
# The credits goes to coreos.
|
|
||||||
# This version is only a (slightly) modified version.
|
|
||||||
#
|
|
||||||
# Thanks to open source and thanks to CoreOS / etcd.
|
|
||||||
#
|
|
||||||
# @link https://github.com/coreos/etcd/blob/master/scripts/build-release
|
|
||||||
#
|
|
||||||
|
|
||||||
VER=$1
|
|
||||||
PROJ="simple-webserver"
|
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
|
||||||
echo "Usage: ${0} VERSION" >> /dev/stderr
|
|
||||||
exit 255
|
|
||||||
fi
|
|
||||||
|
|
||||||
set -u
|
|
||||||
|
|
||||||
function main {
|
|
||||||
mkdir release
|
|
||||||
|
|
||||||
for os in darwin windows linux freebsd; do
|
|
||||||
export GOOS=${os}
|
|
||||||
export GOARCH="amd64"
|
|
||||||
|
|
||||||
TARGET="simple-webserver-${VER}-${GOOS}-${GOARCH}"
|
|
||||||
mkdir ${TARGET}
|
|
||||||
cp README.md ${TARGET}/README.md
|
|
||||||
|
|
||||||
local ext=""
|
|
||||||
if [ ${GOOS} == "windows" ]; then
|
|
||||||
ext=".exe"
|
|
||||||
fi
|
|
||||||
|
|
||||||
go build -o ${TARGET}/simple-webserver${ext}
|
|
||||||
|
|
||||||
if [ ${GOOS} == "linux" ]; then
|
|
||||||
tar cfz release/${TARGET}.tar.gz ${TARGET}
|
|
||||||
echo "Wrote release/${TARGET}.tar.gz"
|
|
||||||
else
|
|
||||||
zip -qr release/${TARGET}.zip ${TARGET}
|
|
||||||
echo "Wrote release/${TARGET}.zip"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
main
|
|
Загрузка…
Ссылка в новой задаче