Gentoo Archives: gentoo-commits

From: "Manuel Rüger" <mrueg@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-cluster/kubeadm/, sys-cluster/kubeadm/files/
Date: Wed, 03 Apr 2019 12:47:21
Message-Id: 1554295594.10fa398c73bd3f6863f8e19db0941386015921b4.mrueg@gentoo
1 commit: 10fa398c73bd3f6863f8e19db0941386015921b4
2 Author: Dan Molik <dan <AT> danmolik <DOT> com>
3 AuthorDate: Wed Apr 3 10:56:18 2019 +0000
4 Commit: Manuel Rüger <mrueg <AT> gentoo <DOT> org>
5 CommitDate: Wed Apr 3 12:46:34 2019 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=10fa398c
7
8 sys-cluster/kubeadm: add openrc support via patch
9
10 Also kubeadm requires go-1.12 to compile
11
12 Package-Manager: Portage-2.3.62, Repoman-2.3.12
13 Signed-off-by: Dan Molik <dan <AT> danmolik.com>
14 Tested-by: Dan Molik <dan <AT> danmolik.com>
15 Signed-off-by: Manuel Rüger <mrueg <AT> gentoo.org>
16
17 .../kubeadm/files/kubeadm-1.14-openrc.patch | 110 +++++++++++++++++++++
18 sys-cluster/kubeadm/kubeadm-1.14.0-r1.ebuild | 50 ++++++++++
19 2 files changed, 160 insertions(+)
20
21 diff --git a/sys-cluster/kubeadm/files/kubeadm-1.14-openrc.patch b/sys-cluster/kubeadm/files/kubeadm-1.14-openrc.patch
22 new file mode 100644
23 index 00000000000..f4da52f0823
24 --- /dev/null
25 +++ b/sys-cluster/kubeadm/files/kubeadm-1.14-openrc.patch
26 @@ -0,0 +1,110 @@
27 +Needed for OpenRC support until https://github.com/kubernetes/kubernetes/pull/73101 is merged.
28 +
29 +Brought to attention by https://bugs.alpinelinux.org/issues/10179
30 +
31 +---------------------------------
32 +--- a/pkg/util/initsystem/initsystem.go
33 ++++ b/pkg/util/initsystem/initsystem.go
34 +@@ -1,5 +1,5 @@
35 + /*
36 +-Copyright 2016 The Kubernetes Authors.
37 ++Copyright 2019 The Kubernetes Authors.
38 +
39 + Licensed under the Apache License, Version 2.0 (the "License");
40 + you may not use this file except in compliance with the License.
41 +@@ -23,6 +23,9 @@
42 + )
43 +
44 + type InitSystem interface {
45 ++ // return a string describing how to enable a service
46 ++ EnableCommand(service string) string
47 ++
48 + // ServiceStart tries to start a specific service
49 + ServiceStart(service string) error
50 +
51 +@@ -42,8 +45,63 @@
52 + ServiceIsActive(service string) bool
53 + }
54 +
55 ++type OpenRCInitSystem struct{}
56 ++
57 ++func (openrc OpenRCInitSystem) ServiceStart(service string) error {
58 ++ args := []string{service, "start"}
59 ++ return exec.Command("rc-service", args...).Run()
60 ++}
61 ++
62 ++func (openrc OpenRCInitSystem) ServiceStop(service string) error {
63 ++ args := []string{service, "stop"}
64 ++ return exec.Command("rc-service", args...).Run()
65 ++}
66 ++
67 ++func (openrc OpenRCInitSystem) ServiceRestart(service string) error {
68 ++ args := []string{service, "restart"}
69 ++ return exec.Command("rc-service", args...).Run()
70 ++}
71 ++
72 ++// openrc writes to stderr if a service is not found or not enabled
73 ++// this is in contrast to systemd which only writes to stdout.
74 ++// Hence, we use the Combinedoutput, and ignore the error.
75 ++func (openrc OpenRCInitSystem) ServiceExists(service string) bool {
76 ++ args := []string{service, "status"}
77 ++ outBytes, _ := exec.Command("rc-service", args...).CombinedOutput()
78 ++ if strings.Contains(string(outBytes), "does not exist") {
79 ++ return false
80 ++ }
81 ++ return true
82 ++}
83 ++
84 ++func (openrc OpenRCInitSystem) ServiceIsEnabled(service string) bool {
85 ++ args := []string{"show", "default"}
86 ++ outBytes, _ := exec.Command("rc-update", args...).Output()
87 ++ if strings.Contains(string(outBytes), service) {
88 ++ return true
89 ++ }
90 ++ return false
91 ++}
92 ++
93 ++func (openrc OpenRCInitSystem) ServiceIsActive(service string) bool {
94 ++ args := []string{service, "status"}
95 ++ outBytes, _ := exec.Command("rc-service", args...).Output()
96 ++ if strings.Contains(string(outBytes), "stopped") {
97 ++ return false
98 ++ }
99 ++ return true
100 ++}
101 ++
102 ++func (openrc OpenRCInitSystem) EnableCommand(service string) string {
103 ++ return fmt.Sprintf("rc-update add %s default", service)
104 ++}
105 ++
106 + type SystemdInitSystem struct{}
107 +
108 ++func (sysd SystemdInitSystem) EnableCommand(service string) string {
109 ++ return fmt.Sprintf("systemctl enable %s.service", service)
110 ++}
111 ++
112 + func (sysd SystemdInitSystem) reloadSystemd() error {
113 + if err := exec.Command("systemctl", "daemon-reload").Run(); err != nil {
114 + return fmt.Errorf("failed to reload systemd: %v", err)
115 +@@ -110,6 +168,10 @@
116 + // WindowsInitSystem is the windows implementation of InitSystem
117 + type WindowsInitSystem struct{}
118 +
119 ++func (sysd WindowsInitSystem) EnableCommand(service string) string {
120 ++ return fmt.Sprintf("Set-Service '%s' -StartupType Automatic", service)
121 ++}
122 ++
123 + func (sysd WindowsInitSystem) ServiceStart(service string) error {
124 + args := []string{"Start-Service", service}
125 + err := exec.Command("powershell", args...).Run()
126 +@@ -170,6 +232,10 @@
127 + _, err := exec.LookPath("systemctl")
128 + if err == nil {
129 + return &SystemdInitSystem{}, nil
130 ++ }
131 ++ _, err = exec.LookPath("openrc")
132 ++ if err == nil {
133 ++ return &OpenRCInitSystem{}, nil
134 + }
135 + _, err = exec.LookPath("wininit.exe")
136 + if err == nil {
137
138 diff --git a/sys-cluster/kubeadm/kubeadm-1.14.0-r1.ebuild b/sys-cluster/kubeadm/kubeadm-1.14.0-r1.ebuild
139 new file mode 100644
140 index 00000000000..763c3838067
141 --- /dev/null
142 +++ b/sys-cluster/kubeadm/kubeadm-1.14.0-r1.ebuild
143 @@ -0,0 +1,50 @@
144 +# Copyright 1999-2019 Gentoo Authors
145 +# Distributed under the terms of the GNU General Public License v2
146 +
147 +EAPI=6
148 +inherit golang-build golang-vcs-snapshot bash-completion-r1
149 +
150 +EGO_PN="k8s.io/kubernetes"
151 +ARCHIVE_URI="https://github.com/kubernetes/kubernetes/archive/v${PV}.tar.gz -> kubernetes-${PV}.tar.gz"
152 +KEYWORDS="~amd64"
153 +
154 +DESCRIPTION="CLI to Easily bootstrap a secure Kubernetes cluster"
155 +HOMEPAGE="https://github.com/kubernetes/kubernetes https://kubernetes.io"
156 +SRC_URI="${ARCHIVE_URI}"
157 +
158 +LICENSE="Apache-2.0"
159 +SLOT="0"
160 +IUSE=""
161 +
162 +DEPEND=">=dev-lang/go-1.12
163 + dev-go/go-bindata"
164 +
165 +RESTRICT="test"
166 +
167 +src_prepare() {
168 + default
169 + sed -i -e "/vendor\/github.com\/jteeuwen\/go-bindata\/go-bindata/d" -e "s/-s -w/-w/" src/${EGO_PN}/hack/lib/golang.sh || die
170 + sed -i -e "/export PATH/d" src/${EGO_PN}/hack/generate-bindata.sh || die
171 + pushd src/${EGO_PN} || die
172 + eapply "${FILESDIR}/${PN}-1.14-openrc.patch"
173 + popd || die
174 +}
175 +
176 +src_compile() {
177 + LDFLAGS="" GOPATH="${WORKDIR}/${P}" emake -j1 -C src/${EGO_PN} WHAT=cmd/${PN} GOFLAGS=-v
178 + pushd src/${EGO_PN} || die
179 + _output/bin/${PN} completion bash > ${PN}.bash || die
180 + _output/bin/${PN} completion zsh > ${PN}.zsh || die
181 + popd || die
182 +}
183 +
184 +src_install() {
185 + pushd src/${EGO_PN} || die
186 + dobin _output/bin/${PN}
187 +
188 + newbashcomp ${PN}.bash ${PN}
189 + insinto /usr/share/zsh/site-functions
190 + newins ${PN}.zsh _${PN}
191 +
192 + popd || die
193 +}