Skip to content

Commit

Permalink
Merge pull request #119 from banzaicloud/airgap
Browse files Browse the repository at this point in the history
Image repository related fixes
  • Loading branch information
sagikazarmark authored Oct 8, 2020
2 parents b3ca246 + d5cfe4b commit 46ee9bd
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func certificateAutoApproverTemplate() string {
" priorityClassName: system-cluster-critical\n" +
" containers:\n" +
" - name: auto-approver\n" +
" image: banzaicloud/auto-approver:0.1.0\n" +
" image: {{ .ImageRepository }}/auto-approver:0.1.0\n" +
" imagePullPolicy: Always\n" +
" env:\n" +
" - name: WATCH_NAMESPACE\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ spec:
priorityClassName: system-cluster-critical
containers:
- name: auto-approver
image: banzaicloud/auto-approver:0.1.0
image: {{ .ImageRepository }}/auto-approver:0.1.0
imagePullPolicy: Always
env:
- name: WATCH_NAMESPACE
Expand Down
6 changes: 3 additions & 3 deletions cmd/pke/app/phases/kubeadm/controlplane/cilium.yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func ciliumTemplate() string {
" key: custom-cni-conf\n" +
" name: cilium-config\n" +
" optional: true\n" +
" image: \"docker.io/cilium/cilium:v1.6.4\"\n" +
" image: \"{{ .ImageRepository }}/cilium:v1.6.4\"\n" +
" imagePullPolicy: IfNotPresent\n" +
" lifecycle:\n" +
" postStart:\n" +
Expand Down Expand Up @@ -477,7 +477,7 @@ func ciliumTemplate() string {
" key: wait-bpf-mount\n" +
" name: cilium-config\n" +
" optional: true\n" +
" image: \"docker.io/cilium/cilium:v1.6.4\"\n" +
" image: \"{{ .ImageRepository }}/cilium:v1.6.4\"\n" +
" imagePullPolicy: IfNotPresent\n" +
" name: clean-cilium-state\n" +
" securityContext:\n" +
Expand Down Expand Up @@ -652,7 +652,7 @@ func ciliumTemplate() string {
" key: identity-allocation-mode\n" +
" name: cilium-config\n" +
" optional: true\n" +
" image: \"docker.io/cilium/operator:v1.6.4\"\n" +
" image: \"{{ .ImageRepository }}/cilium-operator:v1.6.4\"\n" +
" imagePullPolicy: IfNotPresent\n" +
" name: cilium-operator\n" +
" livenessProbe:\n" +
Expand Down
6 changes: 3 additions & 3 deletions cmd/pke/app/phases/kubeadm/controlplane/cilium.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ spec:
key: custom-cni-conf
name: cilium-config
optional: true
image: "docker.io/cilium/cilium:v1.6.4"
image: "{{ .ImageRepository }}/cilium:v1.6.4"
imagePullPolicy: IfNotPresent
lifecycle:
postStart:
Expand Down Expand Up @@ -459,7 +459,7 @@ spec:
key: wait-bpf-mount
name: cilium-config
optional: true
image: "docker.io/cilium/cilium:v1.6.4"
image: "{{ .ImageRepository }}/cilium:v1.6.4"
imagePullPolicy: IfNotPresent
name: clean-cilium-state
securityContext:
Expand Down Expand Up @@ -634,7 +634,7 @@ spec:
key: identity-allocation-mode
name: cilium-config
optional: true
image: "docker.io/cilium/operator:v1.6.4"
image: "{{ .ImageRepository }}/cilium-operator:v1.6.4"
imagePullPolicy: IfNotPresent
name: cilium-operator
livenessProbe:
Expand Down
56 changes: 47 additions & 9 deletions cmd/pke/app/phases/kubeadm/controlplane/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package controlplane

import (
"bytes"
"context"
"crypto/tls"
"encoding/base64"
Expand Down Expand Up @@ -496,7 +497,7 @@ func (c *ControlPlane) Run(out io.Writer) error {
return err
}
case constants.NetworkProviderCilium:
if err := installCilium(out, kubeConfig, c.mtu); err != nil {
if err := installCilium(out, kubeConfig, c.imageRepository, c.mtu); err != nil {
return err
}
}
Expand Down Expand Up @@ -860,7 +861,7 @@ func (c *ControlPlane) installMaster(out io.Writer) error {
}

// apply AutoApprover
if err := writeCertificateAutoApprover(out); err != nil {
if err := writeCertificateAutoApprover(out, c.imageRepository); err != nil {
return err
}
// apply PSP
Expand All @@ -877,7 +878,7 @@ func (c *ControlPlane) installMaster(out io.Writer) error {
}

// apply default storage class
if err := applyDefaultStorageClass(out, c.disableDefaultStorageClass, c.cloudProvider, c.azureStorageAccountType, c.azureStorageKind); err != nil {
if err := applyDefaultStorageClass(out, c.disableDefaultStorageClass, c.cloudProvider, c.azureStorageAccountType, c.azureStorageKind, c.imageRepository); err != nil {
return err
}

Expand Down Expand Up @@ -937,7 +938,7 @@ func installWeave(out io.Writer, cloudProvider, podNetworkCIDR, kubeConfig strin
//go:generate templify -t ${GOTMPL} -p controlplane -f cilium cilium.yaml.tmpl
//go:generate templify -t ${GOTMPL} -p controlplane -f ciliumSysFsBpf cilium_sys_fs_bpf.mount.tmpl

func installCilium(out io.Writer, kubeConfig string, mtu uint) error {
func installCilium(out io.Writer, kubeConfig string, imageRepository string, mtu uint) error {
if _, err := os.Stat("/sys/fs/bpf"); err != nil {
// Mounting BPF filesystem
if err := file.Overwrite(ciliumBpfMountSystemd, ciliumSysFsBpfTemplate()); err != nil {
Expand All @@ -949,11 +950,29 @@ func installCilium(out io.Writer, kubeConfig string, mtu uint) error {
}

// https://raw.githubusercontent.com/cilium/cilium/v1.6/install/kubernetes/quick-install.yaml
input := ciliumTemplate()
tmpl, err := template.New("").Parse(ciliumTemplate())
if err != nil {
return err
}

type data struct {
ImageRepository string
}

d := data{
ImageRepository: imageRepository,
}

var b bytes.Buffer
err = tmpl.Execute(&b, d)
if err != nil {
return err
}

cmd := runner.Cmd(out, cmdKubectl, "apply", "-f", "-")
cmd.Env = append(os.Environ(), "KUBECONFIG="+kubeConfig)
cmd.Stdin = strings.NewReader(input)
_, err := cmd.CombinedOutputAsync()
cmd.Stdin = strings.NewReader(b.String())
_, err = cmd.CombinedOutputAsync()
return err
}

Expand Down Expand Up @@ -1042,7 +1061,7 @@ func taintRemoveNoSchedule(out io.Writer, clusterMode, kubeConfig string) error

//go:generate templify -t ${GOTMPL} -p controlplane -f certificateAutoApprover certificate_auto_approver.yaml.tmpl

func writeCertificateAutoApprover(out io.Writer) error {
func writeCertificateAutoApprover(out io.Writer, imageRepository string) error {
filename := certificateAutoApprover
dir := filepath.Dir(filename)

Expand All @@ -1052,7 +1071,26 @@ func writeCertificateAutoApprover(out io.Writer) error {
return err
}

err = file.Overwrite(filename, certificateAutoApproverTemplate())
tmpl, err := template.New("").Parse(certificateAutoApproverTemplate())
if err != nil {
return err
}

type data struct {
ImageRepository string
}

d := data{
ImageRepository: imageRepository,
}

var b bytes.Buffer
err = tmpl.Execute(&b, d)
if err != nil {
return err
}

err = file.Overwrite(filename, b.String())
if err != nil {
return err
}
Expand Down
14 changes: 9 additions & 5 deletions cmd/pke/app/phases/kubeadm/controlplane/storage_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/banzaicloud/pke/cmd/pke/app/util/runner"
)

func applyDefaultStorageClass(out io.Writer, disableDefaultStorageClass bool, cloudProvider string, azureStorageAccountType, azureStorageKind string) error {
func applyDefaultStorageClass(out io.Writer, disableDefaultStorageClass bool, cloudProvider string, azureStorageAccountType, azureStorageKind string, imageRepository string) error {
if disableDefaultStorageClass {
return nil
}
Expand All @@ -44,7 +44,7 @@ func applyDefaultStorageClass(out io.Writer, disableDefaultStorageClass bool, cl
// TODO: out-of-tree CSI volume plugins
return nil
default:
err = writeStorageClassLocalPathStorage(out, storageClassConfig)
err = writeStorageClassLocalPathStorage(out, storageClassConfig, imageRepository)
}
if err != nil {
return err
Expand Down Expand Up @@ -148,17 +148,21 @@ func writeStorageClassAzure(out io.Writer, filename string, storageAccountType,

//go:generate templify -t ${GOTMPL} -p controlplane -f storageClassLocalPathStorage storage_class_local_path_storage.yaml.tmpl

func writeStorageClassLocalPathStorage(out io.Writer, filename string) error {
func writeStorageClassLocalPathStorage(out io.Writer, filename string, imageRepository string) error {
_, _ = fmt.Fprintf(out, "[%s] creating local default storage class\n", use)

tmpl, err := template.New("storage-class-local-path").Parse(storageClassLocalPathStorageTemplate())
if err != nil {
return err
}

type data struct{}
type data struct {
ImageRepository string
}

d := data{}
d := data{
ImageRepository: imageRepository,
}

return file.WriteTemplate(filename, tmpl, d)
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func storageClassLocalPathStorageTemplate() string {
" serviceAccountName: local-path-provisioner-service-account\n" +
" containers:\n" +
" - name: local-path-provisioner\n" +
" image: banzaicloud/local-path-provisioner:v0.0.9\n" +
" image: {{ .ImageRepository }}/local-path-provisioner:v0.0.9\n" +
" imagePullPolicy: Always\n" +
" command:\n" +
" - local-path-provisioner\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ spec:
serviceAccountName: local-path-provisioner-service-account
containers:
- name: local-path-provisioner
image: banzaicloud/local-path-provisioner:v0.0.9
image: {{ .ImageRepository }}/local-path-provisioner:v0.0.9
imagePullPolicy: Always
command:
- local-path-provisioner
Expand Down
4 changes: 0 additions & 4 deletions cmd/pke/app/util/linux/dnf.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ func (y *DnfInstaller) InstallKubernetesPrerequisites(out io.Writer, kubernetesV
}
}

if _, err := runner.Cmd(out, cmdDnf, "update", "-y").CombinedOutputAsync(); err != nil {
return err
}

return nil
}

Expand Down

0 comments on commit 46ee9bd

Please sign in to comment.