Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#112 from kahun/fix/gcp_security_po…
Browse files Browse the repository at this point in the history
…licy

[EOS-11379] Soportar Kubernetes v1.25
  • Loading branch information
kahun committed May 24, 2023
2 parents 988e213 + a1313fa commit cb201fc
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 279 deletions.
44 changes: 0 additions & 44 deletions pkg/cluster/internal/create/actions/createworker/calico.go

This file was deleted.

21 changes: 18 additions & 3 deletions pkg/cluster/internal/create/actions/createworker/gcp.go
Expand Up @@ -17,11 +17,13 @@ limitations under the License.
package createworker

import (
"bytes"
"context"
_ "embed"
b64 "encoding/base64"
"encoding/json"
"net/url"
"strconv"
"strings"

"google.golang.org/api/compute/v1"
Expand All @@ -32,9 +34,6 @@ import (
"sigs.k8s.io/kind/pkg/exec"
)

//go:embed files/gcp-compute-persistent-disk-csi-driver.yaml
var csiManifest string

type GCPBuilder struct {
capxProvider string
capxVersion string
Expand Down Expand Up @@ -118,6 +117,22 @@ parameters:
type: pd-standard
volumeBindingMode: WaitForFirstConsumer`

// Get workload k8s version
raw := bytes.Buffer{}
errRaw := bytes.Buffer{}
cmd = n.Command("sh", "-c", "kubectl version --short=true --client=false | grep Server | cut -d ':' -f 2")
if err := cmd.SetStdout(&raw).SetStderr(&errRaw).Run(); err != nil || strings.Contains(errRaw.String(), "Error:") || raw.String() == "" {
return errors.Wrap(err, "failed to get workload cluster kubeconfig")
}
res := strings.TrimSpace(strings.ReplaceAll(raw.String(), "v", ""))
version, _ := strconv.ParseFloat(res[0:4], 64)

// Generate CSI manifest
csiManifest, err := getManifest("gcp-compute-persistent-disk-csi-driver.tmpl", version)
if err != nil {
return errors.Wrap(err, "failed to generate CSI manifest")
}

// Create CSI namespace
c = "kubectl --kubeconfig " + k + " create namespace " + b.csiNamespace
err = commons.ExecuteCommand(n, c)
Expand Down
20 changes: 19 additions & 1 deletion pkg/cluster/internal/create/actions/createworker/provider.go
Expand Up @@ -18,6 +18,7 @@ package createworker

import (
"bytes"
"embed"
"encoding/base64"
"reflect"
"strings"
Expand All @@ -29,6 +30,9 @@ import (
"sigs.k8s.io/kind/pkg/errors"
)

//go:embed templates/*
var ctel embed.FS

const (
CAPICoreProvider = "cluster-api:v1.4.1"
CAPIBootstrapProvider = "kubeadm:v1.4.1"
Expand Down Expand Up @@ -110,7 +114,7 @@ func installCalico(n nodes.Node, k string, descriptorFile commons.DescriptorFile
calicoTemplate := "/kind/calico-helm-values.yaml"

// Generate the calico helm values
calicoHelmValues, err := getCalicoManifest(descriptorFile)
calicoHelmValues, err := getManifest("calico-helm-values.tmpl", descriptorFile)
if err != nil {
return errors.Wrap(err, "failed to generate calico helm values")
}
Expand Down Expand Up @@ -325,3 +329,17 @@ func GetClusterManifest(flavor string, params commons.TemplateParams, azs []stri
}
return tpl.String(), nil
}

func getManifest(name string, params interface{}) (string, error) {
var tpl bytes.Buffer
t, err := template.New("").ParseFS(ctel, "templates/"+name)
if err != nil {
return "", err
}

err = t.ExecuteTemplate(&tpl, name, params)
if err != nil {
return "", err
}
return tpl.String(), nil
}

0 comments on commit cb201fc

Please sign in to comment.