Skip to content

Commit

Permalink
remove appArmorProfile for k8s<v1.30.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ComradeProgrammer committed Oct 30, 2024
1 parent 7f5816b commit 184ebc9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
github.com/hashicorp/go-getter v1.7.6
github.com/hashicorp/go-retryablehttp v0.7.7
github.com/hooklift/iso9660 v1.0.0
github.com/icza/dyno v0.0.0-20230330125955-09f820a8d9c0
github.com/jmoiron/sqlx v1.4.0
github.com/johanneswuerbach/nfsexports v0.0.0-20200318065542-c48c3734757f
github.com/juju/clock v1.1.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,8 @@ github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
github.com/icza/dyno v0.0.0-20230330125955-09f820a8d9c0 h1:nHoRIX8iXob3Y2kdt9KsjyIb7iApSvb3vgsd93xb5Ow=
github.com/icza/dyno v0.0.0-20230330125955-09f820a8d9c0/go.mod h1:c1tRKs5Tx7E2+uHGSyyncziFjvGpgv4H2HrqXeUQ/Uk=
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.10/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
Expand Down
41 changes: 36 additions & 5 deletions pkg/minikube/cni/cilium.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ import (
"os/exec"
"text/template"

"github.com/blang/semver/v4"
"github.com/icza/dyno"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
"k8s.io/klog/v2"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/util"
)

// Generated by running `make update-cilium-version`
//
//go:embed cilium.yaml
var ciliumYaml string

var ciliumTmpl = template.Must(template.New("name").Parse(ciliumYaml))

// Cilium is the Cilium CNI manager
type Cilium struct {
cc config.ClusterConfig
Expand All @@ -50,7 +52,15 @@ func (c Cilium) CIDR() string {
}

// GenerateCiliumYAML generates the .yaml file
func GenerateCiliumYAML() ([]byte, error) {
func (c Cilium) GenerateCiliumYAML() ([]byte, error) {

// see issue #19683, older Kubernetes versions cannot recognize appArmorProfile fields
k8sVersion, err := util.ParseKubernetesVersion(c.cc.KubernetesConfig.KubernetesVersion)
if err == nil && k8sVersion.LT(semver.MustParse("1.30.0")) {
if ciliumYaml, err = removeAppArorProfile(ciliumYaml); err != nil {
return nil, err
}
}

podCIDR := DefaultPodCIDR

Expand All @@ -61,7 +71,7 @@ func GenerateCiliumYAML() ([]byte, error) {
}{
PodSubnet: podCIDR,
}

ciliumTmpl := template.Must(template.New("name").Parse(ciliumYaml))
b := bytes.Buffer{}
configTmpl := ciliumTmpl

Expand All @@ -80,10 +90,31 @@ func (c Cilium) Apply(r Runner) error {
return errors.Wrap(err, "bpf mount")
}

ciliumCfg, err := GenerateCiliumYAML()
ciliumCfg, err := c.GenerateCiliumYAML()
if err != nil {
return errors.Wrap(err, "generating cilium cfg")
}

return applyManifest(c.cc, r, manifestAsset(ciliumCfg))
}

func removeAppArorProfile(ciliumConfig string) (string, error) {

Check failure on line 101 in pkg/minikube/cni/cilium.go

View workflow job for this annotation

GitHub Actions / lint

removeAppArorProfile - result 1 (error) is always nil (unparam)
// remove all appArmorProfile fields
decoder := yaml.NewDecoder(bytes.NewBufferString(ciliumConfig))
var buffer bytes.Buffer
encoder := yaml.NewEncoder(&buffer)
for {
obj := map[string]interface{}{}
err := decoder.Decode(&obj)
if err != nil && err.Error() == "EOF" {
// we have unmarshaled all objects
break
} else if err != nil {
panic(err)
}
dyno.Delete(obj, "appArmorProfile", "spec", "template", "spec", "securityContext")

Check failure on line 115 in pkg/minikube/cni/cilium.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `dyno.Delete` is not checked (errcheck)
encoder.Encode(obj)

Check failure on line 116 in pkg/minikube/cni/cilium.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `encoder.Encode` is not checked (errcheck)

}
return buffer.String(), nil
}

0 comments on commit 184ebc9

Please sign in to comment.