Skip to content

Commit

Permalink
chore: bump k8s libs to 0.30 (kyverno#10285)
Browse files Browse the repository at this point in the history
* chore: bump k8s libs to 0.30

Signed-off-by: ShutingZhao <[email protected]>

* chore: update crds

Signed-off-by: ShutingZhao <[email protected]>

* chore: bump kubectl-validate

Signed-off-by: ShutingZhao <[email protected]>

* chore: fix tests

Signed-off-by: ShutingZhao <[email protected]>

* chore: fix panic

Signed-off-by: ShutingZhao <[email protected]>

* chore: fix linter

Signed-off-by: ShutingZhao <[email protected]>

* chore: bump k8s

Signed-off-by: ShutingZhao <[email protected]>

* fix sum

Signed-off-by: Charles-Edouard Brétéché <[email protected]>

* codegen

Signed-off-by: Charles-Edouard Brétéché <[email protected]>

* fix: indent

Signed-off-by: ShutingZhao <[email protected]>

* chore: bump deps

Signed-off-by: ShutingZhao <[email protected]>

---------

Signed-off-by: ShutingZhao <[email protected]>
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
Co-authored-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
realshuting and eddycharly authored Jun 4, 2024
1 parent 7fac162 commit 5260b4f
Show file tree
Hide file tree
Showing 26 changed files with 2,771 additions and 207 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
uid:
description: |-
A unique value that identifies this user across time. If this user is
Expand Down Expand Up @@ -298,6 +299,7 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
uid:
description: |-
A unique value that identifies this user across time. If this user is
Expand Down Expand Up @@ -619,6 +621,7 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
uid:
description: |-
A unique value that identifies this user across time. If this user is
Expand Down Expand Up @@ -678,6 +681,7 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
uid:
description: |-
A unique value that identifies this user across time. If this user is
Expand Down
2 changes: 1 addition & 1 deletion charts/kyverno/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ cleanupJobs:

# -- Node affinity constraints.
nodeAffinity: {}

clusterEphemeralReports:

# -- Enable cleanup cronjob
Expand Down
6 changes: 3 additions & 3 deletions cmd/cli/kubectl-kyverno/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"io/fs"
)

const CrdsFolder = "crds"
const crdsFolder = "crds"

//go:embed crds
var crdsFs embed.FS

func Crds() fs.FS {
return crdsFs
func Crds() (fs.FS, error) {
return fs.Sub(crdsFs, crdsFolder)
}
11 changes: 10 additions & 1 deletion cmd/cli/kubectl-kyverno/exception/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
)

var (
factory, _ = resourceloader.New(openapiclient.NewComposite(openapiclient.NewLocalCRDFiles(data.Crds(), data.CrdsFolder)))
exceptionV2alpha1 = schema.GroupVersion(kyvernov2alpha1.GroupVersion).WithKind("PolicyException")
exceptionV2beta1 = schema.GroupVersion(kyvernov2beta1.GroupVersion).WithKind("PolicyException")
exceptionV2 = schema.GroupVersion(kyvernov2.GroupVersion).WithKind("PolicyException")
Expand Down Expand Up @@ -45,6 +44,16 @@ func load(content []byte) ([]*kyvernov2beta1.PolicyException, error) {
return nil, err
}
var exceptions []*kyvernov2beta1.PolicyException
crds, err := data.Crds()
if err != nil {
return nil, err
}

factory, err := resourceloader.New(openapiclient.NewComposite(openapiclient.NewLocalCRDFiles(crds)))
if err != nil {
return nil, err
}

for _, document := range documents {
gvk, untyped, err := factory.Load(document)
if err != nil {
Expand Down
18 changes: 14 additions & 4 deletions cmd/cli/kubectl-kyverno/policy/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ import (
)

var (
factory, _ = resourceloader.New(openapiclient.NewComposite(
openapiclient.NewHardcodedBuiltins("1.28"),
openapiclient.NewLocalCRDFiles(data.Crds(), data.CrdsFolder),
))
policyV1 = schema.GroupVersion(kyvernov1.GroupVersion).WithKind("Policy")
policyV2 = schema.GroupVersion(kyvernov2beta1.GroupVersion).WithKind("Policy")
clusterPolicyV1 = schema.GroupVersion(kyvernov1.GroupVersion).WithKind("ClusterPolicy")
Expand Down Expand Up @@ -125,6 +121,20 @@ func kubectlValidateLoader(path string, content []byte) (*LoaderResults, error)
return nil, err
}
results := &LoaderResults{}

crds, err := data.Crds()
if err != nil {
return nil, err
}

factory, err := resourceloader.New(openapiclient.NewComposite(
openapiclient.NewHardcodedBuiltins("1.30"),
openapiclient.NewLocalCRDFiles(crds),
))
if err != nil {
return nil, err
}

for _, document := range documents {
gvk, untyped, err := factory.Load(document)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions config/crds/kyverno/kyverno.io_updaterequests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
uid:
description: |-
A unique value that identifies this user across time. If this user is
Expand Down Expand Up @@ -292,6 +293,7 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
uid:
description: |-
A unique value that identifies this user across time. If this user is
Expand Down Expand Up @@ -613,6 +615,7 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
uid:
description: |-
A unique value that identifies this user across time. If this user is
Expand Down Expand Up @@ -672,6 +675,7 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
uid:
description: |-
A unique value that identifies this user across time. If this user is
Expand Down
4 changes: 4 additions & 0 deletions config/install-latest-testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46378,6 +46378,7 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
uid:
description: |-
A unique value that identifies this user across time. If this user is
Expand Down Expand Up @@ -46437,6 +46438,7 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
uid:
description: |-
A unique value that identifies this user across time. If this user is
Expand Down Expand Up @@ -46758,6 +46760,7 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
uid:
description: |-
A unique value that identifies this user across time. If this user is
Expand Down Expand Up @@ -46817,6 +46820,7 @@ spec:
items:
type: string
type: array
x-kubernetes-list-type: atomic
uid:
description: |-
A unique value that identifies this user across time. If this user is
Expand Down
56 changes: 33 additions & 23 deletions ext/resource/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,14 @@ func TestNew(t *testing.T) {
wantErr: true,
}, {
name: "builtin",
client: openapiclient.NewHardcodedBuiltins("1.27"),
client: openapiclient.NewHardcodedBuiltins("1.30"),
want: func() Loader {
validator, err := validator.New(openapiclient.NewHardcodedBuiltins("1.27"))
validator, err := validator.New(openapiclient.NewHardcodedBuiltins("1.30"))
require.NoError(t, err)
return &loader{
validator: validator,
}
}(),
}, {
name: "invalid local",
client: openapiclient.NewLocalCRDFiles(data.Crds(), "blam"),
wantErr: true,
}, {
name: "composite - no clients",
client: openapiclient.NewComposite(),
Expand All @@ -61,22 +57,18 @@ func TestNew(t *testing.T) {
wantErr: true,
}, {
name: "composite - with err client",
client: openapiclient.NewComposite(openapiclient.NewHardcodedBuiltins("1.27"), errClient{}),
wantErr: true,
}, {
name: "composite - invalid local",
client: openapiclient.NewComposite(openapiclient.NewLocalCRDFiles(data.Crds(), "blam")),
client: openapiclient.NewComposite(openapiclient.NewHardcodedBuiltins("1.30"), errClient{}),
wantErr: true,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := New(tt.client)
if (err != nil) != tt.wantErr {
t.Errorf("New() error = %v, wantErr %v", err, tt.wantErr)
t.Errorf("%v failed, New() error = %v, wantErr %v", tt.name, err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("New() = %v, want %v", got, tt.want)
t.Errorf("%v failed, New() = %v, want %v", tt.name, got, tt.want)
}
})
}
Expand Down Expand Up @@ -110,30 +102,48 @@ func Test_loader_Load(t *testing.T) {
want unstructured.Unstructured
wantErr bool
}{{
name: "nil",
loader: newLoader(openapiclient.NewLocalCRDFiles(data.Crds(), "crds")),
name: "nil",
loader: newLoader(func() openapi.Client {
file, _ := data.Crds()
return openapiclient.NewLocalCRDFiles(file)
}(),
),
wantErr: true,
}, {
name: "empty GVK",
loader: newLoader(openapiclient.NewLocalCRDFiles(data.Crds(), "crds")),
name: "empty GVK",
loader: newLoader(func() openapi.Client {
file, _ := data.Crds()
return openapiclient.NewLocalCRDFiles(file)
}(),
),
document: []byte(`foo: bar`),
wantErr: true,
}, {
name: "not yaml",
loader: newLoader(openapiclient.NewLocalCRDFiles(data.Crds(), "crds")),
name: "not yaml",
loader: newLoader(
func() openapi.Client {
file, _ := data.Crds()
return openapiclient.NewLocalCRDFiles(file)
}(),
),
document: []byte(`
foo
bar
- baz`),
wantErr: true,
}, {
name: "unknown GVK",
loader: newLoader(openapiclient.NewLocalCRDFiles(data.Crds(), "crds")),
name: "unknown GVK",
loader: newLoader(
func() openapi.Client {
file, _ := data.Crds()
return openapiclient.NewLocalCRDFiles(file)
}(),
),
document: loadFile("../../../cmd/cli/kubectl-kyverno/_testdata/resources/namespace.yaml"),
wantErr: true,
}, {
name: "bad schema",
loader: newLoader(openapiclient.NewHardcodedBuiltins("1.27")),
loader: newLoader(openapiclient.NewHardcodedBuiltins("1.30")),
document: []byte(`
apiVersion: v1
kind: Namespace
Expand All @@ -145,7 +155,7 @@ func Test_loader_Load(t *testing.T) {
wantErr: true,
}, {
name: "ok",
loader: newLoader(openapiclient.NewHardcodedBuiltins("1.27")),
loader: newLoader(openapiclient.NewHardcodedBuiltins("1.30")),
document: loadFile("../../../cmd/cli/kubectl-kyverno/_testdata/resources/namespace.yaml"),
want: toUnstructured(loadFile("../../../cmd/cli/kubectl-kyverno/_testdata/resources/namespace.yaml")),
}}
Expand Down
Loading

0 comments on commit 5260b4f

Please sign in to comment.