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

add external data provider #134

Merged
merged 19 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion constraint/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ YAML_CONSTANT_GOLANG_FILE := ./pkg/apis/templates/yaml_constant.go
constraint-template-string-constant: manifests
rm -rf $(YAML_CONSTANT_GOLANG_FILE)
bash -c 'echo -en ${FILE_STUB} >> ${YAML_CONSTANT_GOLANG_FILE}'
bash -c 'cat deploy/crds.yaml >> ${YAML_CONSTANT_GOLANG_FILE}'
bash -c 'cat config/crds/templates.gatekeeper.sh_constrainttemplates.yaml >> ${YAML_CONSTANT_GOLANG_FILE}'
bash -c 'echo "\`" >> ${YAML_CONSTANT_GOLANG_FILE}'
sed -i -z "s/\n---\n//g" ${YAML_CONSTANT_GOLANG_FILE}
# Remove trailing spaces. Double $ is to prevent variable expansion in make
sed -i "s/ $$//g" ${YAML_CONSTANT_GOLANG_FILE}

Expand Down
50 changes: 50 additions & 0 deletions constraint/config/crds/externaldata.gatekeeper.sh_providers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.5.0
creationTimestamp: null
name: providers.externaldata.gatekeeper.sh
spec:
group: externaldata.gatekeeper.sh
names:
kind: Provider
listKind: ProviderList
plural: providers
singular: provider
scope: Cluster
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: Provider is the Schema for the Provider API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: ProviderSpec defines the desired state of Provider
sozercan marked this conversation as resolved.
Show resolved Hide resolved
properties:
proxyURL:
description: ProxyURL is the URL of the proxy to use for the provider
sozercan marked this conversation as resolved.
Show resolved Hide resolved
type: string
timeout:
description: Timeout is the timeout for the provider
sozercan marked this conversation as resolved.
Show resolved Hide resolved
type: integer
type: object
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
1 change: 1 addition & 0 deletions constraint/config/crds/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
resources:
- templates.gatekeeper.sh_constrainttemplates.yaml
- externaldata.gatekeeper.sh_providers.yaml

patchesStrategicMerge:
- |-
Expand Down
3 changes: 3 additions & 0 deletions constraint/config/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resources:
- crds/templates.gatekeeper.sh_constrainttemplates.yaml
- crds/externaldata.gatekeeper.sh_providers.yaml
49 changes: 49 additions & 0 deletions constraint/deploy/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,52 @@ status:
plural: ""
conditions: []
storedVersions: []
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.5.0
creationTimestamp: null
name: providers.externaldata.gatekeeper.sh
spec:
group: externaldata.gatekeeper.sh
names:
kind: Provider
listKind: ProviderList
plural: providers
singular: provider
scope: Cluster
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: Provider is the Schema for the Provider API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: ProviderSpec defines the desired state of Provider
properties:
proxyURL:
description: ProxyURL is the URL of the proxy to use for the provider
type: string
timeout:
description: Timeout is the timeout for the provider
type: integer
type: object
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
25 changes: 25 additions & 0 deletions constraint/pkg/apis/addtoscheme_externaldata_v1alpha1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package apis

import (
"github.com/open-policy-agent/frameworks/constraint/pkg/apis/externaldata/v1alpha1"
)

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes, v1alpha1.AddToScheme)
}
21 changes: 21 additions & 0 deletions constraint/pkg/apis/externaldata/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the externaldata v1alpha1 API group
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package,register
// +k8s:defaulter-gen=TypeMeta
// +groupName=externaldata.gatekeeper.sh
package v1alpha1
56 changes: 56 additions & 0 deletions constraint/pkg/apis/externaldata/v1alpha1/provider_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ProviderSpec defines the desired state of Provider
type ProviderSpec struct {
// ProxyURL is the URL of the proxy to use for the provider
ProxyURL string `json:"proxyURL,omitempty"`
// Timeout is the timeout for the provider
Timeout int `json:"timeout,omitempty"`
}

// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:scope=Cluster

// Provider is the Schema for the Provider API
// +k8s:openapi-gen=true
type Provider struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ProviderSpec `json:"spec,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ProviderList contains a list of Provider
type ProviderList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

Items []Provider `json:"items"`
}

func init() {
SchemeBuilder.Register(&Provider{}, &ProviderList{})
}
16 changes: 16 additions & 0 deletions constraint/pkg/apis/externaldata/v1alpha1/provider_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1
47 changes: 47 additions & 0 deletions constraint/pkg/apis/externaldata/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// NOTE: Boilerplate only. Ignore this file.

// Package v1alpha1 contains API Schema definitions for the externaldata v1alpha1 API group
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package,register
// +k8s:conversion-gen=github.com/open-policy-agent/frameworks/constraint/pkg/apis/externaldata
// +k8s:defaulter-gen=TypeMeta
// +groupName=externaldata.gatekeeper.sh
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// SchemeGroupVersion is group version used to register these objects
SchemeGroupVersion = schema.GroupVersion{Group: "externaldata.gatekeeper.sh", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}

localSchemeBuilder = runtime.NewSchemeBuilder(SchemeBuilder.AddToScheme)

AddToScheme = localSchemeBuilder.AddToScheme
)

// Resource is required by pkg/client/listers/...
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
56 changes: 56 additions & 0 deletions constraint/pkg/apis/externaldata/v1alpha1/v1alpha1_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"log"
"os"
"path/filepath"
"testing"

"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
)

var cfg *rest.Config
var c client.Client

func TestMain(m *testing.M) {
t := &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "..", "deploy", "crds.yaml")},
}

err := SchemeBuilder.AddToScheme(scheme.Scheme)
if err != nil {
log.Fatal(err)
}

if cfg, err = t.Start(); err != nil {
log.Fatal(err)
}

if c, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}); err != nil {
log.Fatal(err)
}

code := m.Run()
if err := t.Stop(); err != nil {
log.Fatal(err)
}
os.Exit(code)
}