Merge pull request #241 from erikwilson/helm-airgap

Air-gap chart support
This commit is contained in:
Darren Shepherd 2019-03-20 11:49:18 -07:00 committed by GitHub
commit e54cfc74c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 310 additions and 9 deletions

View File

@ -1,6 +1,7 @@
//go:generate go run types/codegen/cleanup/main.go //go:generate go run types/codegen/cleanup/main.go
//go:generate go run types/codegen/main.go //go:generate go run types/codegen/main.go
//go:generate go fmt pkg/deploy/zz_generated_bindata.go //go:generate go fmt pkg/deploy/zz_generated_bindata.go
//go:generate go fmt pkg/static/zz_generated_bindata.go
//go:generate go fmt pkg/openapi/zz_generated_bindata.go //go:generate go fmt pkg/openapi/zz_generated_bindata.go
package main package main

View File

@ -4,7 +4,7 @@ metadata:
name: traefik name: traefik
namespace: kube-system namespace: kube-system
spec: spec:
chart: stable/traefik chart: https://%{KUBERNETES_API}%/static/charts/traefik-1.64.0.tgz
set: set:
rbac.enabled: "true" rbac.enabled: "true"
ssl.enabled: "true" ssl.enabled: "true"

View File

@ -89,7 +89,7 @@ func corednsYaml() (*asset, error) {
return a, nil return a, nil
} }
var _traefikYaml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x64\xcc\x3d\xae\x02\x31\x0c\x04\xe0\x3e\xa7\xb0\xb6\x7f\xbb\x7a\xa2\x73\x4b\xc3\x09\xe8\x9d\x64\x10\x51\x7e\x36\x8a\xbd\x48\xdc\x1e\x05\x21\x51\x50\xda\xdf\xcc\x48\x4f\x57\x0c\x4d\x7b\x63\xca\x27\x5d\x83\x98\x15\xac\x69\xdf\x1e\xff\x2e\xa7\x16\x99\x2e\x28\xf5\x7c\x97\x61\xae\xc2\x24\x8a\x09\x3b\xa2\x26\x15\x4c\x36\x04\xb7\x94\x3f\xb7\x76\x09\x60\xca\x87\xc7\x9f\x3e\xd5\x50\x9d\x76\x84\x19\x0f\x73\x80\x49\x4d\x7c\xc1\xf6\xad\x29\x6c\x32\xd1\xf0\x12\x56\xb4\xc9\x91\x69\xb1\x71\x60\x79\x83\x6a\xf9\xf9\xbf\x02\x00\x00\xff\xff\x33\xf0\x4f\x34\xb6\x00\x00\x00") var _traefikYaml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x64\xcc\x4d\x4b\xc4\x30\x10\xc6\xf1\x7b\x3e\xc5\xb0\xb0\xc7\x4d\x5c\x14\x0f\x73\x53\x29\x28\x82\x88\x6f\x57\x99\xa6\xa3\x0d\x79\x69\xc8\x4c\x05\x15\xbf\xbb\xb4\xf4\xb6\xc7\x99\xe7\xcf\x8f\x6a\x78\xe3\x26\x61\x2a\x08\xf1\x5c\xac\x27\xd5\xc4\x36\x4c\xee\xeb\x68\x62\x28\x03\xc2\x2d\xa7\x7c\x33\x52\x53\x93\x59\x69\x20\x25\x34\x00\x85\x32\x23\x68\x23\xfe\x08\x71\xbb\xa5\x92\x67\x84\x38\xf7\x7c\x90\x6f\x51\xce\x46\x2a\xfb\x25\xf7\x0b\x80\x30\xaa\x56\x41\xe7\xf6\xbf\xf7\xaf\xd7\xdd\xd3\x43\xf7\xd2\x3d\xbf\x5f\x3d\xde\xfd\xed\x9d\x28\x69\xf0\x6e\x0d\xc5\x6d\xf0\xe1\x68\x2f\x2f\xec\x99\xd5\xcf\x1f\x03\x20\xac\x8b\x05\xd0\x7a\xf2\x96\x0b\xf5\x89\x07\x84\x9d\xb6\x99\x77\xeb\x20\x92\x4e\xfe\xff\x01\x00\x00\xff\xff\xf0\x93\x36\xe7\xe3\x00\x00\x00")
func traefikYamlBytes() ([]byte, error) { func traefikYamlBytes() ([]byte, error) {
return bindataRead( return bindataRead(
@ -204,6 +204,7 @@ type bintree struct {
Func func() (*asset, error) Func func() (*asset, error)
Children map[string]*bintree Children map[string]*bintree
} }
var _bintree = &bintree{nil, map[string]*bintree{ var _bintree = &bintree{nil, map[string]*bintree{
"coredns.yaml": &bintree{corednsYaml, map[string]*bintree{}}, "coredns.yaml": &bintree{corednsYaml, map[string]*bintree{}},
"traefik.yaml": &bintree{traefikYaml, map[string]*bintree{}}, "traefik.yaml": &bintree{traefikYaml, map[string]*bintree{}},
@ -255,4 +256,3 @@ func _filePath(dir, name string) string {
cannonicalName := strings.Replace(name, "\\", "/", -1) cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
} }

View File

@ -24,7 +24,7 @@ import (
const ( const (
namespace = "kube-system" namespace = "kube-system"
image = "rancher/klipper-helm:v0.1.3" image = "rancher/klipper-helm:v0.1.4"
label = "helm.k3s.cattle.io/chart" label = "helm.k3s.cattle.io/chart"
) )

File diff suppressed because one or more lines are too long

View File

@ -2,6 +2,7 @@ package server
import ( import (
"net/http" "net/http"
"path/filepath"
"strconv" "strconv"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@ -15,6 +16,7 @@ const (
binaryMediaType = "application/octet-stream" binaryMediaType = "application/octet-stream"
pbMediaType = "application/com.github.proto-openapi.spec.v2@v1.0+protobuf" pbMediaType = "application/com.github.proto-openapi.spec.v2@v1.0+protobuf"
openapiPrefix = "openapi." openapiPrefix = "openapi."
staticURL = "/static/"
) )
type CACertsGetter func() (string, error) type CACertsGetter func() (string, error)
@ -28,8 +30,10 @@ func router(serverConfig *config.Control, tunnel http.Handler, cacertsGetter CAC
authed.Path("/v1-k3s/node.key").Handler(nodeKey(serverConfig)) authed.Path("/v1-k3s/node.key").Handler(nodeKey(serverConfig))
authed.Path("/v1-k3s/config").Handler(configHandler(serverConfig)) authed.Path("/v1-k3s/config").Handler(configHandler(serverConfig))
staticDir := filepath.Join(serverConfig.DataDir, "static")
router := mux.NewRouter() router := mux.NewRouter()
router.NotFoundHandler = authed router.NotFoundHandler = authed
router.PathPrefix(staticURL).Handler(serveStatic(staticURL, staticDir))
router.Path("/cacerts").Handler(cacerts(cacertsGetter)) router.Path("/cacerts").Handler(cacerts(cacertsGetter))
router.Path("/openapi/v2").Handler(serveOpenapi()) router.Path("/openapi/v2").Handler(serveOpenapi())
router.Path("/ping").Handler(ping()) router.Path("/ping").Handler(ping())
@ -110,3 +114,7 @@ func ping() http.Handler {
resp.Write(data) resp.Write(data)
}) })
} }
func serveStatic(urlPrefix, staticDir string) http.Handler {
return http.StripPrefix(urlPrefix, http.FileServer(http.Dir(staticDir)))
}

View File

@ -19,11 +19,12 @@ import (
"github.com/rancher/k3s/pkg/deploy" "github.com/rancher/k3s/pkg/deploy"
"github.com/rancher/k3s/pkg/helm" "github.com/rancher/k3s/pkg/helm"
"github.com/rancher/k3s/pkg/servicelb" "github.com/rancher/k3s/pkg/servicelb"
"github.com/rancher/k3s/pkg/static"
"github.com/rancher/k3s/pkg/tls" "github.com/rancher/k3s/pkg/tls"
appsv1 "github.com/rancher/k3s/types/apis/apps/v1" appsv1 "github.com/rancher/k3s/types/apis/apps/v1"
batchv1 "github.com/rancher/k3s/types/apis/batch/v1" batchv1 "github.com/rancher/k3s/types/apis/batch/v1"
corev1 "github.com/rancher/k3s/types/apis/core/v1" corev1 "github.com/rancher/k3s/types/apis/core/v1"
"github.com/rancher/k3s/types/apis/k3s.cattle.io/v1" v1 "github.com/rancher/k3s/types/apis/k3s.cattle.io/v1"
rbacv1 "github.com/rancher/k3s/types/apis/rbac.authorization.k8s.io/v1" rbacv1 "github.com/rancher/k3s/types/apis/rbac.authorization.k8s.io/v1"
"github.com/rancher/norman" "github.com/rancher/norman"
"github.com/rancher/norman/pkg/clientaccess" "github.com/rancher/norman/pkg/clientaccess"
@ -118,6 +119,10 @@ func startNorman(ctx context.Context, config *Config) (string, error) {
func(ctx context.Context) error { func(ctx context.Context) error {
return servicelb.Register(ctx, norman.GetServer(ctx).K8sClient, !config.DisableServiceLB) return servicelb.Register(ctx, norman.GetServer(ctx).K8sClient, !config.DisableServiceLB)
}, },
func(ctx context.Context) error {
dataDir := filepath.Join(controlConfig.DataDir, "static")
return static.Stage(dataDir)
},
func(ctx context.Context) error { func(ctx context.Context) error {
dataDir := filepath.Join(controlConfig.DataDir, "manifests") dataDir := filepath.Join(controlConfig.DataDir, "manifests")
templateVars := map[string]string{"%{CLUSTER_DNS}%": controlConfig.ClusterDNS.String()} templateVars := map[string]string{"%{CLUSTER_DNS}%": controlConfig.ClusterDNS.String()}

27
pkg/static/stage.go Normal file
View File

@ -0,0 +1,27 @@
package static
import (
"io/ioutil"
"os"
"path/filepath"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
func Stage(dataDir string) error {
for _, name := range AssetNames() {
content, err := Asset(name)
if err != nil {
return err
}
p := filepath.Join(dataDir, name)
logrus.Info("Writing static file: ", p)
os.MkdirAll(filepath.Dir(p), 0700)
if err := ioutil.WriteFile(p, content, 0600); err != nil {
return errors.Wrapf(err, "failed to write to %s", name)
}
}
return nil
}

File diff suppressed because one or more lines are too long

View File

@ -1,10 +1,17 @@
#!/bin/bash #!/bin/bash
ROOT_VERSION=v0.0.1
source $(dirname $0)/version.sh source $(dirname $0)/version.sh
cd $(dirname $0)/.. cd $(dirname $0)/..
ROOT_VERSION=v0.0.1
TRAEFIK_VERSION=1.64.0
CHARTS_DIR=build/static/charts
mkdir -p ${CHARTS_DIR}
curl --compressed -sfL https://github.com/ibuildthecloud/k3s-root/releases/download/${ROOT_VERSION}/k3s-root-${ARCH}.tar | tar xf - curl --compressed -sfL https://github.com/ibuildthecloud/k3s-root/releases/download/${ROOT_VERSION}/k3s-root-${ARCH}.tar | tar xf -
ln -sf pigz bin/unpigz ln -sf pigz bin/unpigz
TRAEFIK_FILE=traefik-${TRAEFIK_VERSION}.tgz
curl -sfL https://kubernetes-charts.storage.googleapis.com/${TRAEFIK_FILE} -o ${CHARTS_DIR}/${TRAEFIK_FILE}

View File

@ -48,6 +48,22 @@ func main() {
logrus.Fatal(err) logrus.Fatal(err)
} }
bc = &bindata.Config{
Input: []bindata.InputConfig{
{
Path: "build/static",
Recursive: true,
},
},
Package: "static",
NoMetadata: true,
Prefix: "build/static/",
Output: "pkg/static/zz_generated_bindata.go",
}
if err := bindata.Translate(bc); err != nil {
logrus.Fatal(err)
}
bc = &bindata.Config{ bc = &bindata.Config{
Input: []bindata.InputConfig{ Input: []bindata.InputConfig{
{ {