Skip to content

Commit

Permalink
Merge pull request #134 from sozercan/feat-externaldata2
Browse files Browse the repository at this point in the history
  • Loading branch information
sozercan committed Oct 4, 2021
2 parents f653a9c + c3ff133 commit bdb068f
Show file tree
Hide file tree
Showing 21 changed files with 919 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ bin
*.swo
*~
.output/

.staging
7 changes: 6 additions & 1 deletion constraint/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ manifests:
paths="./pkg/..." \
output:crd:artifacts:config=config/crds
kustomize build config/crds --output=deploy/crds.yaml
mkdir -p .staging/templatecrd
cp config/crds/* .staging/templatecrd
sed -i '/- externaldata.gatekeeper.sh_providers.yaml/d' .staging/templatecrd/kustomization.yaml
kustomize build .staging/templatecrd --output=.staging/templatecrd/crd.yaml

lint:
golangci-lint -v run ./... --timeout 5m
Expand Down Expand Up @@ -76,10 +80,11 @@ YAML_CONSTANT_GOLANG_FILE := ./pkg/schema/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 .staging/templatecrd/crd.yaml >> ${YAML_CONSTANT_GOLANG_FILE}'
bash -c 'echo "\`" >> ${YAML_CONSTANT_GOLANG_FILE}'
# Remove trailing spaces. Double $ is to prevent variable expansion in make
sed -i "s/ $$//g" ${YAML_CONSTANT_GOLANG_FILE}
rm -rf .staging
generate-defaults: constraint-template-string-constant
defaulter-gen \
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: Spec defines the Provider specifications.
properties:
timeout:
description: Timeout is the timeout when querying the provider.
type: integer
url:
description: URL is the url for the provider. URL is prefixed with http:// or https://.
type: string
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ spec:
metadata:
type: object
spec:
description: ConstraintTemplateSpec defines the desired state of ConstraintTemplate
description: ConstraintTemplateSpec defines the desired state of ConstraintTemplate.
properties:
crd:
properties:
Expand Down Expand Up @@ -73,7 +73,7 @@ spec:
type: array
type: object
status:
description: ConstraintTemplateStatus defines the observed state of ConstraintTemplate
description: ConstraintTemplateStatus defines the observed state of ConstraintTemplate.
properties:
byPod:
items:
Expand Down Expand Up @@ -125,7 +125,7 @@ spec:
metadata:
type: object
spec:
description: ConstraintTemplateSpec defines the desired state of ConstraintTemplate
description: ConstraintTemplateSpec defines the desired state of ConstraintTemplate.
properties:
crd:
properties:
Expand Down Expand Up @@ -168,7 +168,7 @@ spec:
type: array
type: object
status:
description: ConstraintTemplateStatus defines the observed state of ConstraintTemplate
description: ConstraintTemplateStatus defines the observed state of ConstraintTemplate.
properties:
byPod:
items:
Expand Down Expand Up @@ -220,7 +220,7 @@ spec:
metadata:
type: object
spec:
description: ConstraintTemplateSpec defines the desired state of ConstraintTemplate
description: ConstraintTemplateSpec defines the desired state of ConstraintTemplate.
properties:
crd:
properties:
Expand Down Expand Up @@ -263,7 +263,7 @@ spec:
type: array
type: object
status:
description: ConstraintTemplateStatus defines the observed state of ConstraintTemplate
description: ConstraintTemplateStatus defines the observed state of ConstraintTemplate.
properties:
byPod:
items:
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
61 changes: 55 additions & 6 deletions constraint/deploy/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ spec:
metadata:
type: object
spec:
description: ConstraintTemplateSpec defines the desired state of ConstraintTemplate
description: ConstraintTemplateSpec defines the desired state of ConstraintTemplate.
properties:
crd:
properties:
Expand Down Expand Up @@ -71,7 +71,7 @@ spec:
type: array
type: object
status:
description: ConstraintTemplateStatus defines the observed state of ConstraintTemplate
description: ConstraintTemplateStatus defines the observed state of ConstraintTemplate.
properties:
byPod:
items:
Expand Down Expand Up @@ -123,7 +123,7 @@ spec:
metadata:
type: object
spec:
description: ConstraintTemplateSpec defines the desired state of ConstraintTemplate
description: ConstraintTemplateSpec defines the desired state of ConstraintTemplate.
properties:
crd:
properties:
Expand Down Expand Up @@ -166,7 +166,7 @@ spec:
type: array
type: object
status:
description: ConstraintTemplateStatus defines the observed state of ConstraintTemplate
description: ConstraintTemplateStatus defines the observed state of ConstraintTemplate.
properties:
byPod:
items:
Expand Down Expand Up @@ -218,7 +218,7 @@ spec:
metadata:
type: object
spec:
description: ConstraintTemplateSpec defines the desired state of ConstraintTemplate
description: ConstraintTemplateSpec defines the desired state of ConstraintTemplate.
properties:
crd:
properties:
Expand Down Expand Up @@ -261,7 +261,7 @@ spec:
type: array
type: object
status:
description: ConstraintTemplateStatus defines the observed state of ConstraintTemplate
description: ConstraintTemplateStatus defines the observed state of ConstraintTemplate.
properties:
byPod:
items:
Expand Down 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: Spec defines the Provider specifications.
properties:
timeout:
description: Timeout is the timeout when querying the provider.
type: integer
url:
description: URL is the url for the provider. URL is prefixed with http:// or https://.
type: string
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
58 changes: 58 additions & 0 deletions constraint/pkg/apis/externaldata/v1alpha1/provider_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
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 {
// URL is the url for the provider. URL is prefixed with http:// or https://.
URL string `json:"url,omitempty"`
// Timeout is the timeout when querying 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 defines the Provider specifications.
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 contains the list of Providers.
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
Loading

0 comments on commit bdb068f

Please sign in to comment.