Skip to content

Commit 287e0f4

Browse files
Prepare for initial release
1 parent 2e250c3 commit 287e0f4

31 files changed

+1619
-51
lines changed

.dockerignore

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
./bin
2+
./build
3+
./pkg/data/zz_generated_bindata.go
4+
./package/data.tar.gz
25
./.vagrant
36
./.dapper
47
./data-dir
58
./dist
69
./.trash-cache
7-
./image/root
8-
./image/agent
9-
./image/go_build_agent
10-
./image/main.squashfs

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
/image/go_build_agent
1414
/image/main.squashfs
1515
/package/k3s
16+
/package/data.tar.gz
1617
/pkg/data/zz_generated_bindata.go
1718
__pycache__
1819
/tests/.pytest_cache/

Dockerfile.dapper

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
FROM golang:1.11-alpine3.8
1+
FROM golang:1.11.4-alpine3.8
2+
# FROM arm=golang@sha256:fe81149b4e7f07ecb558fd16cdbcdb11e739846a046e38cc6e170aa39a67e7ec arm64=golang@sha256:da9c2d140ed4bf911ef8f6d9437912b80497c256ef2235c65836eac83d1c0ce7
23

34
RUN apk -U --no-cache add bash git gcc musl-dev docker vim less file curl wget ca-certificates jq linux-headers zlib-dev tar zip squashfs-tools npm coreutils \
45
python3 py3-pip python3-dev openssl-dev libffi-dev libseccomp libseccomp-dev make
56
RUN pip3 install 'tox==3.6.0'
67
RUN apk -U --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/main/ add sqlite-dev sqlite-static
78
RUN go get -d golang.org/x/lint/golint && \
89
git -C /go/src/golang.org/x/lint/golint checkout -b current 06c8688daad7faa9da5a0c2f163a3d14aac986ca && \
9-
go install golang.org/x/lint/golint && \
10-
rm -rf /go/src /go/pkg
10+
go install golang.org/x/lint/golint
1111
RUN go get -d github.com/alecthomas/gometalinter && \
1212
git -C /go/src/github.com/alecthomas/gometalinter checkout -b current v2.0.11 && \
1313
go install github.com/alecthomas/gometalinter && \
14-
gometalinter --install && \
15-
rm -rf /go/src /go/pkg
14+
gometalinter --install
15+
RUN rm -rf /go/src /go/pkg
1616

17+
ARG DAPPER_HOST_ARCH
18+
ENV ARCH $DAPPER_HOST_ARCH
1719
ENV DAPPER_RUN_ARGS --privileged
1820
ENV DAPPER_ENV REPO TAG DRONE_TAG IMAGE_NAME
1921
ENV DAPPER_SOURCE /go/src/github.com/rancher/k3s/

cmd/k3s/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ func getAssetAndDir(dataDir string) (string, string) {
7272
}
7373

7474
func extract(asset, dir string) error {
75-
logrus.Infof("Asset dir %s", dir)
75+
logrus.Debugf("Asset dir %s", dir)
7676

7777
if _, err := os.Stat(dir); err == nil {
7878
return nil
7979
}
8080

81-
logrus.Infof("Staging to dir %s", dir)
81+
logrus.Infof("Preparing data dir %s", dir)
8282

8383
content, err := data.Asset(asset)
8484
if err != nil {

docker-compose.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: '3'
2+
services:
3+
server:
4+
image: rancher/k3s:fa08d60-dirty-amd64
5+
command: server --disable-agent
6+
environment:
7+
- K3S_CLUSTER_SECRET=somethingtotallyrandom
8+
- K3S_KUBECONFIG_OUTPUT=/output/kubeconfig.yaml
9+
- K3S_KUBECONFIG_MODE=666
10+
volumes:
11+
- k3s-server:/var/lib/rancher/k3s
12+
# This is just so that we get the kubeconfig file out
13+
- .:/output
14+
ports:
15+
- 6443:6443
16+
17+
node:
18+
image: rancher/k3s:fa08d60-dirty-amd64
19+
tmpfs:
20+
- /run
21+
- /var/run
22+
privileged: true
23+
environment:
24+
- K3S_URL=https://server:6443
25+
- K3S_CLUSTER_SECRET=somethingtotallyrandom
26+
27+
volumes:
28+
k3s-server: {}

manifests/coredns.yaml

+175
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: coredns
5+
namespace: kube-system
6+
---
7+
apiVersion: rbac.authorization.k8s.io/v1beta1
8+
kind: ClusterRole
9+
metadata:
10+
labels:
11+
kubernetes.io/bootstrapping: rbac-defaults
12+
name: system:coredns
13+
rules:
14+
- apiGroups:
15+
- ""
16+
resources:
17+
- endpoints
18+
- services
19+
- pods
20+
- namespaces
21+
verbs:
22+
- list
23+
- watch
24+
- apiGroups:
25+
- ""
26+
resources:
27+
- nodes
28+
verbs:
29+
- get
30+
---
31+
apiVersion: rbac.authorization.k8s.io/v1beta1
32+
kind: ClusterRoleBinding
33+
metadata:
34+
annotations:
35+
rbac.authorization.kubernetes.io/autoupdate: "true"
36+
labels:
37+
kubernetes.io/bootstrapping: rbac-defaults
38+
name: system:coredns
39+
roleRef:
40+
apiGroup: rbac.authorization.k8s.io
41+
kind: ClusterRole
42+
name: system:coredns
43+
subjects:
44+
- kind: ServiceAccount
45+
name: coredns
46+
namespace: kube-system
47+
---
48+
apiVersion: v1
49+
kind: ConfigMap
50+
metadata:
51+
name: coredns
52+
namespace: kube-system
53+
data:
54+
Corefile: |
55+
.:53 {
56+
errors
57+
health
58+
kubernetes cluster.local in-addr.arpa ip6.arpa {
59+
pods insecure
60+
upstream
61+
fallthrough in-addr.arpa ip6.arpa
62+
}
63+
prometheus :9153
64+
proxy . 1.1.1.1
65+
cache 30
66+
loop
67+
reload
68+
loadbalance
69+
}
70+
---
71+
apiVersion: extensions/v1beta1
72+
kind: Deployment
73+
metadata:
74+
name: coredns
75+
namespace: kube-system
76+
labels:
77+
k8s-app: kube-dns
78+
kubernetes.io/name: "CoreDNS"
79+
spec:
80+
#replicas: 1
81+
strategy:
82+
type: RollingUpdate
83+
rollingUpdate:
84+
maxUnavailable: 1
85+
selector:
86+
matchLabels:
87+
k8s-app: kube-dns
88+
template:
89+
metadata:
90+
labels:
91+
k8s-app: kube-dns
92+
spec:
93+
serviceAccountName: coredns
94+
tolerations:
95+
- key: "CriticalAddonsOnly"
96+
operator: "Exists"
97+
nodeSelector:
98+
beta.kubernetes.io/os: linux
99+
containers:
100+
- name: coredns
101+
image: coredns/coredns:1.3.0
102+
imagePullPolicy: IfNotPresent
103+
resources:
104+
limits:
105+
memory: 170Mi
106+
requests:
107+
cpu: 100m
108+
memory: 70Mi
109+
args: [ "-conf", "/etc/coredns/Corefile" ]
110+
volumeMounts:
111+
- name: config-volume
112+
mountPath: /etc/coredns
113+
readOnly: true
114+
ports:
115+
- containerPort: 53
116+
name: dns
117+
protocol: UDP
118+
- containerPort: 53
119+
name: dns-tcp
120+
protocol: TCP
121+
- containerPort: 9153
122+
name: metrics
123+
protocol: TCP
124+
securityContext:
125+
allowPrivilegeEscalation: false
126+
capabilities:
127+
add:
128+
- NET_BIND_SERVICE
129+
drop:
130+
- all
131+
readOnlyRootFilesystem: true
132+
livenessProbe:
133+
httpGet:
134+
path: /health
135+
port: 8080
136+
scheme: HTTP
137+
initialDelaySeconds: 60
138+
timeoutSeconds: 5
139+
successThreshold: 1
140+
failureThreshold: 5
141+
dnsPolicy: Default
142+
volumes:
143+
- name: config-volume
144+
configMap:
145+
name: coredns
146+
items:
147+
- key: Corefile
148+
path: Corefile
149+
---
150+
apiVersion: v1
151+
kind: Service
152+
metadata:
153+
name: kube-dns
154+
namespace: kube-system
155+
annotations:
156+
prometheus.io/port: "9153"
157+
prometheus.io/scrape: "true"
158+
labels:
159+
k8s-app: kube-dns
160+
kubernetes.io/cluster-service: "true"
161+
kubernetes.io/name: "CoreDNS"
162+
spec:
163+
selector:
164+
k8s-app: kube-dns
165+
clusterIP: 10.43.0.10
166+
ports:
167+
- name: dns
168+
port: 53
169+
protocol: UDP
170+
- name: dns-tcp
171+
port: 53
172+
protocol: TCP
173+
- name: metrics
174+
port: 9153
175+
protocol: TCP

pkg/agent/config/config.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212
"path/filepath"
1313
"time"
1414

15-
"k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
16-
1715
"github.com/pkg/errors"
1816
"github.com/rancher/k3s/pkg/cli/cmds"
1917
"github.com/rancher/k3s/pkg/daemons/config"
@@ -22,6 +20,7 @@ import (
2220
"k8s.io/apimachinery/pkg/util/json"
2321
"k8s.io/apimachinery/pkg/util/net"
2422
"k8s.io/client-go/util/cert"
23+
"k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
2524
)
2625

2726
func Get(ctx context.Context, agent cmds.Agent) *config.Node {

pkg/agent/run.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
"path/filepath"
77
"time"
88

9-
"github.com/sirupsen/logrus"
10-
119
"github.com/rancher/k3s/pkg/agent/config"
1210
"github.com/rancher/k3s/pkg/agent/containerd"
1311
"github.com/rancher/k3s/pkg/agent/flannel"
@@ -17,6 +15,7 @@ import (
1715
"github.com/rancher/k3s/pkg/cli/cmds"
1816
"github.com/rancher/k3s/pkg/daemons/agent"
1917
"github.com/rancher/norman/pkg/clientaccess"
18+
"github.com/sirupsen/logrus"
2019
)
2120

2221
func run(ctx context.Context, cfg cmds.Agent) error {
@@ -65,6 +64,10 @@ func run(ctx context.Context, cfg cmds.Agent) error {
6564
func Run(ctx context.Context, cfg cmds.Agent) error {
6665
cfg.DataDir = filepath.Join(cfg.DataDir, "agent")
6766

67+
if cfg.ClusterSecret != "" {
68+
cfg.Token = "K10node:" + cfg.ClusterSecret
69+
}
70+
6871
for {
6972
tmpFile, err := clientaccess.AgentAccessInfoToTempKubeConfig("", cfg.ServerURL, cfg.Token)
7073
if err != nil {

pkg/cli/agent/agent.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func Run(ctx *cli.Context) error {
1717
return fmt.Errorf("agent must be ran as root")
1818
}
1919

20-
if cmds.AgentConfig.Token == "" {
20+
if cmds.AgentConfig.Token == "" && cmds.AgentConfig.ClusterSecret == "" {
2121
return fmt.Errorf("--token is required")
2222
}
2323

pkg/cli/cmds/agent.go

+15-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import (
88
)
99

1010
type Agent struct {
11-
Token string
12-
ServerURL string
13-
DataDir string
14-
NodeIP string
15-
NodeName string
16-
Docker bool
17-
NoFlannel bool
18-
Debug bool
11+
Token string
12+
ServerURL string
13+
DataDir string
14+
NodeIP string
15+
NodeName string
16+
ClusterSecret string
17+
Docker bool
18+
NoFlannel bool
19+
Debug bool
1920
AgentShared
2021
}
2122

@@ -74,6 +75,12 @@ func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command {
7475
Usage: "Disable embedded flannel",
7576
Destination: &AgentConfig.NoFlannel,
7677
},
78+
cli.StringFlag{
79+
Name: "cluster-secret",
80+
Usage: "Shared secret used to bootstrap a cluster",
81+
Destination: &AgentConfig.ClusterSecret,
82+
EnvVar: "K3S_CLUSTER_SECRET",
83+
},
7784
NodeNameFlag,
7885
NodeIPFlag,
7986
},

0 commit comments

Comments
 (0)