-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pipeline Kubernetes Engine initial commit
- Loading branch information
Showing
84 changed files
with
4,601 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
**/.vagrant* | ||
.DS_Store | ||
/.idea/ | ||
/bin/ | ||
/build/ | ||
/test.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
SHELL = /bin/bash | ||
|
||
# Project variables | ||
PACKAGE = github.com/banzaicloud/pke | ||
|
||
# Build variables | ||
BUILD_DIR ?= $(PWD)/build | ||
VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null || git symbolic-ref -q --short HEAD) | ||
COMMIT_HASH ?= $(shell git rev-parse --short HEAD 2>/dev/null) | ||
BUILD_DATE ?= $(shell date +%FT%T%z) | ||
GIT_TREE_STATE ?= $(shell if [[ -z `git status --porcelain 2>/dev/null` ]]; then echo "clean"; else echo "dirty"; fi ) | ||
LDFLAGS += -X main.Version=${VERSION} -X main.CommitHash=${COMMIT_HASH} -X main.BuildDate=${BUILD_DATE} -X main.GitTreeState=${GIT_TREE_STATE} | ||
|
||
.PHONY: pke | ||
pke: GOARGS += -tags "${GOTAGS}" -ldflags "${LDFLAGS}" -o ${BUILD_DIR}/pke | ||
pke: ## Build PKE binary | ||
cd cmd/pke/ && go build ${GOARGS} ${PACKAGE}/cmd/pke | ||
|
||
.PHONY: pke-docs | ||
pke-docs: ## Generate documentation for PKE | ||
rm -rf cmd/pke/docs/*.md | ||
cd cmd/pke/docs/ && go run -v generate.go | ||
|
||
.PHONY: test | ||
test: export CGO_ENABLED = 1 | ||
test: | ||
set -o pipefail; go list ./... | xargs -n1 go test ${GOARGS} -v -parallel 1 2>&1 | tee test.txt | ||
|
||
|
||
.PHONY: help | ||
.DEFAULT_GOAL := help | ||
help: | ||
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cmd | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewPKECommand(in io.Reader, out io.Writer, gitVersion, gitCommit, gitTreeState, buildDate string) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "pke", | ||
Short: "Bootstrap a secure Kubernetes cluster with Banzai Cloud Pipeline Kubernetes Engine (PKE)", | ||
SilenceUsage: true, | ||
DisableAutoGenTag: true, | ||
} | ||
|
||
cmd.ResetFlags() | ||
|
||
cmd.AddCommand(NewCmdInstall(out)) | ||
cmd.AddCommand(NewCmdImage(out)) | ||
cmd.AddCommand(NewCmdToken(out)) | ||
cmd.AddCommand(NewCmdVersion(out, gitVersion, gitCommit, gitTreeState, buildDate)) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package cmd | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/banzaicloud/pke/cmd/pke/app/constants" | ||
"github.com/banzaicloud/pke/cmd/pke/app/phases" | ||
"github.com/banzaicloud/pke/cmd/pke/app/phases/kubeadm/controlplane" | ||
"github.com/banzaicloud/pke/cmd/pke/app/phases/kubeadm/node" | ||
"github.com/banzaicloud/pke/cmd/pke/app/phases/kubeadm/version" | ||
"github.com/banzaicloud/pke/cmd/pke/app/phases/pipeline/certificates" | ||
"github.com/banzaicloud/pke/cmd/pke/app/phases/pipeline/ready" | ||
"github.com/banzaicloud/pke/cmd/pke/app/phases/runtime/container" | ||
"github.com/banzaicloud/pke/cmd/pke/app/phases/runtime/kubernetes" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewCmdVersion provides the version information of banzai-cloud-pke. | ||
func NewCmdInstall(out io.Writer) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "install", | ||
Short: "Install a single Banzai Cloud Pipeline Kubernetes Engine (PKE) machine", | ||
Args: cobra.NoArgs, | ||
} | ||
|
||
cmd.AddCommand(single(out)) | ||
cmd.AddCommand(master(out)) | ||
cmd.AddCommand(worker(out)) | ||
|
||
return cmd | ||
} | ||
|
||
func master(out io.Writer) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "master", | ||
Short: "Installs Banzai Cloud Pipeline Kubernetes Engine (PKE) Master node", | ||
RunE: phases.RunEAllSubcommands, | ||
} | ||
|
||
cmd.AddCommand(version.NewCommand(out)) | ||
cmd.AddCommand(container.NewCommand(out)) | ||
cmd.AddCommand(kubernetes.NewCommand(out)) | ||
cmd.AddCommand(certificates.NewCommand(out)) | ||
cmd.AddCommand(controlplane.NewCommand(out)) | ||
cmd.AddCommand(ready.NewCommand(out, ready.RoleMaster)) | ||
|
||
phases.MakeRunnable(cmd) | ||
|
||
return cmd | ||
} | ||
|
||
func single(out io.Writer) *cobra.Command { | ||
m := master(out) | ||
m.Use = "single" | ||
m.Short = "Installs Banzai Cloud Pipeline Kubernetes Engine (PKE) on a single machine" | ||
_ = m.Flags().Set(constants.FlagClusterMode, "single") | ||
|
||
return m | ||
} | ||
|
||
func worker(out io.Writer) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "worker", | ||
Short: "Installs Banzai Cloud Pipeline Kubernetes Engine (PKE) Worker node", | ||
RunE: phases.RunEAllSubcommands, | ||
} | ||
|
||
cmd.AddCommand(version.NewCommand(out)) | ||
cmd.AddCommand(container.NewCommand(out)) | ||
cmd.AddCommand(kubernetes.NewCommand(out)) | ||
cmd.AddCommand(node.NewCommand(out)) | ||
cmd.AddCommand(ready.NewCommand(out, ready.RoleWorker)) | ||
|
||
phases.MakeRunnable(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package cmd | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/banzaicloud/pke/cmd/pke/app/phases" | ||
"github.com/banzaicloud/pke/cmd/pke/app/phases/kubeadm/images" | ||
"github.com/banzaicloud/pke/cmd/pke/app/phases/kubeadm/version" | ||
"github.com/banzaicloud/pke/cmd/pke/app/phases/runtime/container" | ||
"github.com/banzaicloud/pke/cmd/pke/app/phases/runtime/kubernetes" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewCmdImage . | ||
func NewCmdImage(out io.Writer) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "machine-image", | ||
Short: "Machine image build helper for Banzai Cloud Pipeline Kubernetes Engine (PKE)", | ||
RunE: phases.RunEAllSubcommands, | ||
} | ||
|
||
cmd.AddCommand(version.NewCommand(out)) | ||
cmd.AddCommand(container.NewCommand(out)) | ||
cmd.AddCommand(kubernetes.NewCommand(out)) | ||
cmd.AddCommand(images.NewCommand(out)) | ||
|
||
phases.MakeRunnable(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cmd | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/banzaicloud/pke/cmd/pke/app/phases/kubeadm/token/create" | ||
"github.com/banzaicloud/pke/cmd/pke/app/phases/kubeadm/token/list" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewCmdVersion provides the version information of banzai-cloud-pke. | ||
func NewCmdToken(out io.Writer) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "token", | ||
Short: "Manage Kubernetes bootstrap tokens", | ||
Args: cobra.NoArgs, | ||
} | ||
|
||
cmd.AddCommand(create.NewCommand(out)) | ||
cmd.AddCommand(list.NewCommand(out)) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"runtime" | ||
|
||
"github.com/banzaicloud/pke/cmd/pke/app/constants" | ||
"github.com/ghodss/yaml" | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type ClientVersion struct { | ||
GitVersion string `json:"gitVersion"` | ||
GitCommit string `json:"gitCommit"` | ||
GitTreeState string `json:"gitTreeState"` | ||
BuildDate string `json:"buildDate"` | ||
GoVersion string `json:"goVersion"` | ||
Compiler string `json:"compiler"` | ||
Platform string `json:"platform"` | ||
} | ||
|
||
// NewCmdVersion provides the version information of banzai-cloud-pke. | ||
func NewCmdVersion(out io.Writer, gitVersion, gitCommit, gitTreeState, buildDate string) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "version", | ||
Short: "Print tool version", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return RunVersion(out, cmd, gitVersion, gitCommit, gitTreeState, buildDate) | ||
}, | ||
} | ||
cmd.Flags().StringP(constants.FlagOutput, constants.FlagOutputShort, "", "Output format; available options are 'yaml', 'json' and 'short'") | ||
return cmd | ||
} | ||
|
||
func RunVersion(out io.Writer, cmd *cobra.Command, gitVersion, gitCommit, gitTreeState, buildDate string) error { | ||
of, err := cmd.Flags().GetString(constants.FlagOutput) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
v := struct { | ||
ClientVersion `json:"clientVersion"` | ||
}{ClientVersion{ | ||
GitVersion: gitVersion, | ||
GitCommit: gitCommit, | ||
BuildDate: buildDate, | ||
GitTreeState: gitTreeState, | ||
GoVersion: runtime.Version(), | ||
Compiler: runtime.Compiler, | ||
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), | ||
}} | ||
|
||
switch of { | ||
case "": | ||
_, _ = fmt.Fprintf(out, "kubeadm version: %#v\n", v) | ||
case "short": | ||
_, _ = fmt.Fprintf(out, "%s\n", v.GitVersion) | ||
case "yaml": | ||
y, err := yaml.Marshal(&v) | ||
if err != nil { | ||
return err | ||
} | ||
_, _ = fmt.Fprintln(out, string(y)) | ||
case "json": | ||
y, err := json.MarshalIndent(&v, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
_, _ = fmt.Fprintln(out, string(y)) | ||
default: | ||
return errors.Errorf("invalid output format: %s", of) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package constants | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
) | ||
|
||
const ( | ||
// FlagOutput output formatting. | ||
FlagOutput = "output" | ||
// FlagOutputShort output formatting. | ||
FlagOutputShort = "o" | ||
|
||
// FlagPipelineAPIEndpoint Pipeline API url. | ||
FlagPipelineAPIEndpoint = "pipeline-url" | ||
// FlagPipelineAPIEndpointShort Pipeline API url. | ||
FlagPipelineAPIEndpointShort = "u" | ||
|
||
// FlagPipelineAPIToken token for accessing Pipeline API. | ||
FlagPipelineAPIToken = "pipeline-token" | ||
// FlagPipelineAPITokenShort token for accessing Pipeline API. | ||
FlagPipelineAPITokenShort = "t" | ||
|
||
// FlagPipelineOrganizationID organization id in Pipeline. | ||
FlagPipelineOrganizationID = "pipeline-org-id" | ||
// FlagPipelineClusterID cluster id in Pipeline. | ||
FlagPipelineClusterID = "pipeline-cluster-id" | ||
|
||
// FlagPipelineNodepool name of the nodepool the node belongs to. | ||
FlagPipelineNodepool = "pipeline-nodepool" | ||
|
||
// FlagAPIServerHostPort Kubernetes advertise address API server and Etcd uses this. | ||
FlagAdvertiseAddress = "kubernetes-advertise-address" | ||
// FlagAPIServerHostPort Kubernetes API Server in host port format. | ||
FlagAPIServerHostPort = "kubernetes-api-server" | ||
// FlagKubeadmToken kubeadm token. | ||
FlagKubeadmToken = "kubernetes-node-token" | ||
// FlagCACertHash Kubernetes API Server CA Cert hash. | ||
FlagCACertHash = "kubernetes-api-server-ca-cert-hash" | ||
// FlagAPIServerCertSANs sets extra Subject Alternative Names for the API Server signing cert. | ||
FlagAPIServerCertSANs = "kubernetes-api-server-cert-sans" | ||
// FlagControllerManagerSigningCA Kubernetes Controller Manager needs a single signing cert. | ||
// This is needed when using Intermediate CAs. | ||
FlagControllerManagerSigningCA = "kubernetes-controller-manager-signing-ca" | ||
|
||
// FlagKubernetesVersion Kubernetes version. | ||
FlagKubernetesVersion = "kubernetes-version" | ||
|
||
// FlagNetworkProvider network provider for Kubernetes. | ||
FlagNetworkProvider = "kubernetes-network-provider" | ||
// FlagServiceCIDR range of IP address for service VIPs. | ||
FlagServiceCIDR = "kubernetes-service-cidr" | ||
// FlagPodNetworkCIDR range of IP addresses for the pod network. | ||
FlagPodNetworkCIDR = "kubernetes-pod-network-cidr" | ||
// FlagInfrastructureCIDR range of IP addresses from which the advertise address can be calculated using system's network interfaces. | ||
FlagInfrastructureCIDR = "kubernetes-infrastructure-cidr" | ||
|
||
// FlagCloudProvider cloud provider for kubeadm. | ||
FlagCloudProvider = "kubernetes-cloud-provider" | ||
|
||
// FlagClusterName cluster name | ||
FlagClusterName = "kubernetes-cluster-name" | ||
|
||
// FlagOIDCIssuerURL OIDC issuer URL | ||
FlagOIDCIssuerURL = "kubernetes-oidc-issuer-url" | ||
// FlagOIDCClientID OIDC client ID | ||
FlagOIDCClientID = "kubernetes-oidc-client-id" | ||
|
||
// FlagClusterMode possible values: single, default, ha. | ||
FlagClusterMode = "kubernetes-master-mode" | ||
|
||
// CloudProviderAmazon | ||
CloudProviderAmazon = "aws" | ||
|
||
// FlagImageRepository prefix for image repository. | ||
FlagImageRepository = "image-repository" | ||
) | ||
|
||
var ( | ||
ErrUnsupportedOS = errors.New("unsupported operating system") | ||
ErrInvalidInput = errors.New("invalid input") | ||
ErrValidationFailed = errors.New("validation failed") | ||
ErrUnsupportedNetworkProvider = errors.New("unsupported network provider") | ||
ErrUnsupportedKubernetesVersion = errors.New("unsupported kubernetes version") | ||
) |
Oops, something went wrong.