Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ValidatingAdmissionPolicy generation function #376

Merged
merged 5 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions constraint/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.18
require (
github.com/davecgh/go-spew v1.1.1
github.com/golang/glog v1.1.1
github.com/google/cel-go v0.16.1
github.com/google/go-cmp v0.5.9
github.com/onsi/gomega v1.27.7
github.com/open-policy-agent/opa v0.57.1
Expand All @@ -17,7 +16,7 @@ require (
k8s.io/apimachinery v0.28.3
k8s.io/apiserver v0.28.3
k8s.io/client-go v0.28.3
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
sigs.k8s.io/controller-runtime v0.15.0
sigs.k8s.io/yaml v1.3.0
)
Expand All @@ -44,6 +43,7 @@ require (
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/cel-go v0.16.1 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions constraint/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg=
k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 h1:LyMgNKD2P8Wn1iAwQU5OhxCKlKJy0sHc+PcDwFB24dQ=
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9/go.mod h1:wZK2AVp1uHCp4VamDVgBP2COHZjqD1T68Rf0CM3YjSM=
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 h1:qY1Ad8PODbnymg2pRbkyMT/ylpTrCM8P2RJ0yroCyIk=
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.1.2 h1:trsWhjU5jZrx6UvFu4WzQDrN7Pga4a7Qg+zcfcj64PA=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.1.2/go.mod h1:+qG7ISXqCDVVcyO8hLn12AKVYYUjM7ftlqsqmrhMZE0=
sigs.k8s.io/controller-runtime v0.15.0 h1:ML+5Adt3qZnMSYxZ7gAverBLNPSMQEibtzAgp0UPojU=
Expand Down
20 changes: 10 additions & 10 deletions constraint/pkg/apis/templates/v1/constrainttemplate_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

func TestStorageConstraintTemplate(t *testing.T) {
Expand Down Expand Up @@ -637,22 +637,22 @@ func TestValidationVersionConversionAndTransformation(t *testing.T) {
{
name: "Two deep properties, LegacySchema=true",
v: &Validation{
LegacySchema: pointer.Bool(true),
LegacySchema: ptr.To[bool](true),
OpenAPIV3Schema: schema.VersionedIncompleteSchema(),
},
exp: &templates.Validation{
LegacySchema: pointer.Bool(true),
LegacySchema: ptr.To[bool](true),
OpenAPIV3Schema: schema.VersionlessSchemaWithXPreserve(),
},
},
{
name: "Two deep properties, LegacySchema=false",
v: &Validation{
LegacySchema: pointer.Bool(false),
LegacySchema: ptr.To[bool](false),
OpenAPIV3Schema: schema.VersionedIncompleteSchema(),
},
exp: &templates.Validation{
LegacySchema: pointer.Bool(false),
LegacySchema: ptr.To[bool](false),
OpenAPIV3Schema: schema.VersionlessSchema(),
},
},
Expand All @@ -668,24 +668,24 @@ func TestValidationVersionConversionAndTransformation(t *testing.T) {
{
name: "Nil properties, LegacySchema=true",
v: &Validation{
LegacySchema: pointer.Bool(true),
LegacySchema: ptr.To[bool](true),
OpenAPIV3Schema: nil,
},
exp: &templates.Validation{
LegacySchema: pointer.Bool(true),
LegacySchema: ptr.To[bool](true),
OpenAPIV3Schema: &apiextensions.JSONSchemaProps{
XPreserveUnknownFields: pointer.Bool(true),
XPreserveUnknownFields: ptr.To[bool](true),
},
},
},
{
name: "Nil properties, LegacySchema=false",
v: &Validation{
LegacySchema: pointer.Bool(false),
LegacySchema: ptr.To[bool](false),
OpenAPIV3Schema: nil,
},
exp: &templates.Validation{
LegacySchema: pointer.Bool(false),
LegacySchema: ptr.To[bool](false),
OpenAPIV3Schema: nil,
},
},
Expand Down
4 changes: 2 additions & 2 deletions constraint/pkg/apis/templates/v1/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/open-policy-agent/frameworks/constraint/pkg/schema"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

func TestToVersionless(t *testing.T) {
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestToVersionless(t *testing.T) {
},
Validation: &templates.Validation{
// A default was applied
LegacySchema: pointer.Bool(false),
LegacySchema: ptr.To[bool](false),
OpenAPIV3Schema: schema.VersionlessSchema(),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

func TestStorageConstraintTemplate(t *testing.T) {
Expand Down Expand Up @@ -637,22 +637,22 @@ func TestValidationVersionConversionAndTransformation(t *testing.T) {
{
name: "Two deep properties, LegacySchema=true",
v: &Validation{
LegacySchema: pointer.Bool(true),
LegacySchema: ptr.To[bool](true),
OpenAPIV3Schema: schema.VersionedIncompleteSchema(),
},
exp: &templates.Validation{
LegacySchema: pointer.Bool(true),
LegacySchema: ptr.To[bool](true),
OpenAPIV3Schema: schema.VersionlessSchemaWithXPreserve(),
},
},
{
name: "Two deep properties, LegacySchema=false",
v: &Validation{
LegacySchema: pointer.Bool(false),
LegacySchema: ptr.To[bool](false),
OpenAPIV3Schema: schema.VersionedIncompleteSchema(),
},
exp: &templates.Validation{
LegacySchema: pointer.Bool(false),
LegacySchema: ptr.To[bool](false),
OpenAPIV3Schema: schema.VersionlessSchema(),
},
},
Expand All @@ -668,24 +668,24 @@ func TestValidationVersionConversionAndTransformation(t *testing.T) {
{
name: "Nil properties, LegacySchema=true",
v: &Validation{
LegacySchema: pointer.Bool(true),
LegacySchema: ptr.To[bool](true),
OpenAPIV3Schema: nil,
},
exp: &templates.Validation{
LegacySchema: pointer.Bool(true),
LegacySchema: ptr.To[bool](true),
OpenAPIV3Schema: &apiextensions.JSONSchemaProps{
XPreserveUnknownFields: pointer.Bool(true),
XPreserveUnknownFields: ptr.To[bool](true),
},
},
},
{
name: "Nil properties, LegacySchema=false",
v: &Validation{
LegacySchema: pointer.Bool(false),
LegacySchema: ptr.To[bool](false),
OpenAPIV3Schema: nil,
},
exp: &templates.Validation{
LegacySchema: pointer.Bool(false),
LegacySchema: ptr.To[bool](false),
OpenAPIV3Schema: nil,
},
},
Expand Down
4 changes: 2 additions & 2 deletions constraint/pkg/apis/templates/v1alpha1/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/open-policy-agent/frameworks/constraint/pkg/schema"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

func TestToVersionless(t *testing.T) {
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestToVersionless(t *testing.T) {
},
Validation: &templates.Validation{
// A default was applied
LegacySchema: pointer.Bool(true),
LegacySchema: ptr.To[bool](true),
OpenAPIV3Schema: schema.VersionlessSchemaWithXPreserve(),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

func TestStorageConstraintTemplate(t *testing.T) {
Expand Down Expand Up @@ -637,22 +637,22 @@ func TestValidationVersionConversionAndTransformation(t *testing.T) {
{
name: "Two deep properties, LegacySchema=true",
v: &Validation{
LegacySchema: pointer.Bool(true),
LegacySchema: ptr.To[bool](true),
OpenAPIV3Schema: schema.VersionedIncompleteSchema(),
},
exp: &templates.Validation{
LegacySchema: pointer.Bool(true),
LegacySchema: ptr.To[bool](true),
OpenAPIV3Schema: schema.VersionlessSchemaWithXPreserve(),
},
},
{
name: "Two deep properties, LegacySchema=false",
v: &Validation{
LegacySchema: pointer.Bool(false),
LegacySchema: ptr.To[bool](false),
OpenAPIV3Schema: schema.VersionedIncompleteSchema(),
},
exp: &templates.Validation{
LegacySchema: pointer.Bool(false),
LegacySchema: ptr.To[bool](false),
OpenAPIV3Schema: schema.VersionlessSchema(),
},
},
Expand All @@ -668,24 +668,24 @@ func TestValidationVersionConversionAndTransformation(t *testing.T) {
{
name: "Nil properties, LegacySchema=true",
v: &Validation{
LegacySchema: pointer.Bool(true),
LegacySchema: ptr.To[bool](true),
OpenAPIV3Schema: nil,
},
exp: &templates.Validation{
LegacySchema: pointer.Bool(true),
LegacySchema: ptr.To[bool](true),
OpenAPIV3Schema: &apiextensions.JSONSchemaProps{
XPreserveUnknownFields: pointer.Bool(true),
XPreserveUnknownFields: ptr.To[bool](true),
},
},
},
{
name: "Nil properties, LegacySchema=false",
v: &Validation{
LegacySchema: pointer.Bool(false),
LegacySchema: ptr.To[bool](false),
OpenAPIV3Schema: nil,
},
exp: &templates.Validation{
LegacySchema: pointer.Bool(false),
LegacySchema: ptr.To[bool](false),
OpenAPIV3Schema: nil,
},
},
Expand Down
4 changes: 2 additions & 2 deletions constraint/pkg/apis/templates/v1beta1/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/open-policy-agent/frameworks/constraint/pkg/schema"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

func TestToVersionless(t *testing.T) {
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestToVersionless(t *testing.T) {
},
Validation: &templates.Validation{
// A default was applied
LegacySchema: pointer.Bool(true),
LegacySchema: ptr.To[bool](true),
OpenAPIV3Schema: schema.VersionlessSchemaWithXPreserve(),
},
},
Expand Down
24 changes: 12 additions & 12 deletions constraint/pkg/client/client_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/open-policy-agent/frameworks/constraint/pkg/core/templates"
"github.com/open-policy-agent/frameworks/constraint/pkg/handler/handlertest"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

func TestMultiDriverAddTemplate(t *testing.T) {
Expand Down Expand Up @@ -58,7 +58,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
driverC := fake.New("driverC")

client, err := NewClient(
Targets(&handlertest.Handler{Name: pointer.String("h1")}),
Targets(&handlertest.Handler{Name: ptr.To[string]("h1")}),
Driver(driverA),
Driver(driverB),
Driver(driverC),
Expand Down Expand Up @@ -739,7 +739,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
driverC := fake.New("driverC")

client, err := NewClient(
Targets(&handlertest.Handler{Name: pointer.String("h1")}),
Targets(&handlertest.Handler{Name: ptr.To[string]("h1")}),
Driver(driverC),
Driver(driverB),
Driver(driverA),
Expand Down Expand Up @@ -826,7 +826,7 @@ func TestMultiDriverRemoveTemplate(t *testing.T) {
driverC := fake.New("driverC")

client, err := NewClient(
Targets(&handlertest.Handler{Name: pointer.String("h1")}),
Targets(&handlertest.Handler{Name: ptr.To[string]("h1")}),
Driver(driverA),
Driver(driverB),
Driver(driverC),
Expand Down Expand Up @@ -907,7 +907,7 @@ func TestDriverForTemplate(t *testing.T) {
{
name: "One Driver",
options: []Opt{
Targets(&handlertest.Handler{Name: pointer.String("h1")}),
Targets(&handlertest.Handler{Name: ptr.To[string]("h1")}),
Driver(fake.New("driverA")),
},
template: cts.New(cts.OptTargets(
Expand All @@ -921,7 +921,7 @@ func TestDriverForTemplate(t *testing.T) {
{
name: "One Driver, Mismatch",
options: []Opt{
Targets(&handlertest.Handler{Name: pointer.String("h1")}),
Targets(&handlertest.Handler{Name: ptr.To[string]("h1")}),
Driver(fake.New("driverA")),
},
template: cts.New(cts.OptTargets(
Expand All @@ -935,7 +935,7 @@ func TestDriverForTemplate(t *testing.T) {
{
name: "Multi Driver",
options: []Opt{
Targets(&handlertest.Handler{Name: pointer.String("h1")}),
Targets(&handlertest.Handler{Name: ptr.To[string]("h1")}),
Driver(fake.New("driverA")),
Driver(fake.New("driverB")),
},
Expand All @@ -950,7 +950,7 @@ func TestDriverForTemplate(t *testing.T) {
{
name: "Multi Driver, Second",
options: []Opt{
Targets(&handlertest.Handler{Name: pointer.String("h1")}),
Targets(&handlertest.Handler{Name: ptr.To[string]("h1")}),
Driver(fake.New("driverB")),
Driver(fake.New("driverA")),
},
Expand All @@ -965,7 +965,7 @@ func TestDriverForTemplate(t *testing.T) {
{
name: "One Driver, Multi-Template",
options: []Opt{
Targets(&handlertest.Handler{Name: pointer.String("h1")}),
Targets(&handlertest.Handler{Name: ptr.To[string]("h1")}),
Driver(fake.New("driverA")),
},
template: cts.New(cts.OptTargets(
Expand All @@ -980,7 +980,7 @@ func TestDriverForTemplate(t *testing.T) {
{
name: "One Driver, Multi-Template Second",
options: []Opt{
Targets(&handlertest.Handler{Name: pointer.String("h1")}),
Targets(&handlertest.Handler{Name: ptr.To[string]("h1")}),
Driver(fake.New("driverB")),
},
template: cts.New(cts.OptTargets(
Expand All @@ -995,7 +995,7 @@ func TestDriverForTemplate(t *testing.T) {
{
name: "Two Driver, Multi-Template",
options: []Opt{
Targets(&handlertest.Handler{Name: pointer.String("h1")}),
Targets(&handlertest.Handler{Name: ptr.To[string]("h1")}),
Driver(fake.New("driverA")),
Driver(fake.New("driverB")),
},
Expand All @@ -1011,7 +1011,7 @@ func TestDriverForTemplate(t *testing.T) {
{
name: "Two Driver, Multi-Template, Second",
options: []Opt{
Targets(&handlertest.Handler{Name: pointer.String("h1")}),
Targets(&handlertest.Handler{Name: ptr.To[string]("h1")}),
Driver(fake.New("driverB")),
Driver(fake.New("driverA")),
},
Expand Down
Loading
Loading