Skip to content

Commit

Permalink
Publish release v1.0.2-rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
fjammes committed Jul 18, 2023
1 parent f856e5c commit 84691d8
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/kind-helper

/.kind-helper
dist/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

Helper to install Kubernetes clusters, based on [kind], on any Linux system. Allow to easily setup:
- multi-nodes cluster
- set CNI plugin and enable NetworkPolicies
- enable PodSecurityPolicy admission control plugin.
- use of Calico CNI
- use of an insecure private registry

Can be used for VMs launched by a CI/CD platform, including [Github Action](https://github.com/k8s-school/kind-helper/actions?query=workflow%3A"CI")

Expand Down
4 changes: 2 additions & 2 deletions cmd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Copyright © 2023 Fabrice Jammes [email protected]
package cmd

import (
"github.com/k8s-school/kind-helper/scripts"
"github.com/k8s-school/kind-helper/resources"
"github.com/spf13/cobra"
)

Expand All @@ -21,7 +21,7 @@ to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
logger.Info("Install ArgoCD")

ExecCmd(scripts.ArgoCDInstallScript)
ExecCmd(resources.ArgoCDInstallScript)
},
}

Expand Down
45 changes: 8 additions & 37 deletions cmd/configgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"os"

"github.com/k8s-school/kind-helper/resources"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -28,10 +29,11 @@ on .kind-helper high-level configuration file
}

type KindHelperConfig struct {
ExtraMountPath string `mapstructure:"extramountpath"`
LocalCertSANs bool `mapstructure:"localcertsans"`
UseCalico bool `mapstructure:"usecalico"`
Workers uint `mapstructure:"workers"`
ExtraMountPath string `mapstructure:"extramountpath"`
LocalCertSANs bool `mapstructure:"localcertsans"`
PrivateRegistry string `mapstructure:"privateregistry"`
UseCalico bool `mapstructure:"usecalico"`
Workers uint `mapstructure:"workers"`
}

func init() {
Expand Down Expand Up @@ -65,6 +67,7 @@ func getKindHelperConfig() KindHelperConfig {

func generateKindConfigFile(c KindHelperConfig) {
logger.Infof("Generate kind configuration file: %s", kindConfigFile)
logger.Debugf("for configuration: %v", c)

f, e := os.Create(kindConfigFile)
if e != nil {
Expand All @@ -80,38 +83,6 @@ func applyTemplate(sc KindHelperConfig) string {

// TODO check https://github.com/helm/helm/blob/main/pkg/chartutil/values.go

cfgTpl := `kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
{{- if .UseCalico }}
networking:
disableDefaultCNI: true # disable kindnet
podSubnet: "192.168.0.0/16"
{{- end }}
kubeadmConfigPatches:
- |
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
metadata:
name: config
apiServer:
extraArgs:
enable-admission-plugins: NodeRestriction,ResourceQuota
{{- if .LocalCertSANs }}
certSANs:
- "127.0.0.1"
{{- end }}
nodes:
- role: control-plane
{{- if .ExtraMountPath }}
extraMounts:
- hostPath: {{ .ExtraMountPath }}
containerPath: /mnt/extra
{{- end }}
{{- range $val := Iterate .Workers }}
- role: worker
{{- end }}
`

kindconfig := format(cfgTpl, &sc)
kindconfig := format(resources.KindConfigTemplate, &sc)
return kindconfig
}
1 change: 1 addition & 0 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
func createCluster() {

c := getKindHelperConfig()
logConfiguration()
generateKindConfigFile(c)

cmd_tpl := "kind create cluster --config %v"
Expand Down
4 changes: 2 additions & 2 deletions cmd/olm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Copyright © 2023 Fabrice Jammes [email protected]
package cmd

import (
"github.com/k8s-school/kind-helper/scripts"
"github.com/k8s-school/kind-helper/resources"
"github.com/spf13/cobra"
)

Expand All @@ -21,7 +21,7 @@ to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
logger.Info("Instal OLM")

ExecCmd(scripts.OlmInstallScript)
ExecCmd(resources.OlmInstallScript)
},
}

Expand Down
8 changes: 7 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,15 @@ func initConfig() {
}

// If a config file is found, read it in.

if err := viper.MergeInConfig(); err == nil {
logger.Debugf("Find user custom configuration %s", viper.ConfigFileUsed())
} else {
logger.Debugf("Do not find user custom configuration %s", viper.ConfigFileUsed())
if _, err := os.Stat(viper.ConfigFileUsed()); err == nil {
logger.Fatalf("Unable to read user custom configuration %s, %v", viper.ConfigFileUsed(), err)
} else {
logger.Debugf("Do not find user custom configuration %s, %v", viper.ConfigFileUsed(), err)
}
}

}
2 changes: 1 addition & 1 deletion cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func logConfiguration() {
if err != nil {
logger.Fatalf("unable to marshal kind-helper configuration to YAML: %v", err)
}
logger.Infof("Current finkctl configuration:\n%s", bs)
logger.Infof("Current kind-helper configuration:\n%s", bs)
}

func format(s string, v interface{}) string {
Expand Down
17 changes: 12 additions & 5 deletions dot-kind-helper.example
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# TODO update me!
kind:
# Use host directory to share container images
# extraMountContainerd: true
# Use host directory to share data between host and kind nodes
# host directory will be mounted on /mnt/extra on each node
# extraMountPath: /path/to/host/directory

# Sets "127.0.0.1" as an extra Subject Alternative Names (SANs) for the API Server signing certificate.
# See https://kubernetes.io/docs/reference/config-api/kubeadm-config.v1beta3/#kubeadm-k8s-io-v1beta3-APIServer
localcertsans: true
# Usefull to access API server through a ssh tunnel
localcertsans: false

# Use calico CNI instead of kindnet
# useCalico: true
# Number of worker nodes
workers: 6
workers: 0

# Supported only for mononode cluster
# Certificates must be available on kind host at "/etc/docker/certs.d/{{ .PrivateRegistry }}"
privateRegistry: "docker-registry.docker-registry:5000"


2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ KUBECTL_VERSION="v1.25.0"
KIND_BIN="/usr/local/bin/kind"
KIND_VERSION="v0.15.0"
KINDHELPER_BIN="/usr/local/bin/kind-helper"
KINDHELPER_VERSION='v1.0.1'
KINDHELPER_VERSION='v1.0.2-rc1'

# If kind exists, compare current version to desired one
if [ -e $KIND_BIN ]; then
Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion scripts/constants.go → resources/constants.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package scripts
package resources

import (
_ "embed"
Expand All @@ -9,3 +9,6 @@ var OlmInstallScript string

//go:embed argocd-install.sh
var ArgoCDInstallScript string

//go:embed kind-config.yaml
var KindConfigTemplate string
36 changes: 36 additions & 0 deletions resources/kind-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
{{- if .PrivateRegistry }}
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.configs."{{ .PrivateRegistry }}".tls]
insecure_skip_verify = true
{{- end }}
{{- if .UseCalico }}
networking:
disableDefaultCNI: true # disable kindnet
podSubnet: "192.168.0.0/16"
{{- end }}
kubeadmConfigPatches:
- |
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
metadata:
name: config
apiServer:
extraArgs:
enable-admission-plugins: NodeRestriction,ResourceQuota
{{- if .LocalCertSANs }}
certSANs:
- "127.0.0.1"
{{- end }}
nodes:
- role: control-plane
extraMounts:
{{- if .ExtraMountPath }}
- hostPath: {{ .ExtraMountPath }}
containerPath: /mnt/extra
{{- end }}
{{- range $val := Iterate .Workers }}
- role: worker
{{- end }}
File renamed without changes.

0 comments on commit 84691d8

Please sign in to comment.