Skip to content

Commit

Permalink
feat: bump up Policy CRD to v1beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
binbin-li committed Sep 21, 2023
1 parent 9731e9c commit c6398a0
Show file tree
Hide file tree
Showing 18 changed files with 695 additions and 69 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ delete-demo-constraints:

.PHONY: deploy-rego-policy
deploy-rego-policy:
kubectl apply -f ./config/samples/policy/config_v1alpha1_policy_rego.yaml
kubectl apply -f ./config/samples/policy/config_v1beta1_policy_rego.yaml

.PHONY: deploy-gatekeeper
deploy-gatekeeper:
Expand Down
12 changes: 11 additions & 1 deletion api/unversioned/policy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
type PolicySpec struct {
// Important: Run "make" to regenerate code after modifying this file

// Type of the polocy
// Type of the policy
Type string `json:"type,omitempty"`

// Parameters for this policy
Expand All @@ -36,6 +36,16 @@ type PolicySpec struct {
type PolicyStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Is successful while applying the policy.
IsSuccess bool `json:"issuccess"`

// Error message if policy is not successfully applied.
// +optional
Error string `json:"error,omitempty"`
// Truncated error message if the message is too long
// +optional
BriefError string `json:"brieferror,omitempty"`
}

// Policy is the Schema for the policies API
Expand Down
54 changes: 54 additions & 0 deletions api/v1alpha1/policy_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright The Ratify Authors.
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 (
unversioned "github.com/deislabs/ratify/api/unversioned"
conversion "k8s.io/apimachinery/pkg/conversion"
)

//nolint:revive // ignore linter for autogenerated code
func Convert_unversioned_PolicySpec_To_v1alpha1_PolicySpec(in *unversioned.PolicySpec, out *PolicySpec, _ conversion.Scope) error {
out.Parameters = in.Parameters
return nil
}

//nolint:revive // ignore linter for autogenerated code
func Convert_unversioned_PolicyStatus_To_v1alpha1_PolicyStatus(in *unversioned.PolicyStatus, out *PolicyStatus, _ conversion.Scope) error {
return nil
}

//nolint:revive // ignore linter for autogenerated code
func Convert_unversioned_Policy_To_v1alpha1_Policy(in *unversioned.Policy, out *Policy, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.ObjectMeta.Name = in.Spec.Type
if err := Convert_unversioned_PolicySpec_To_v1alpha1_PolicySpec(&in.Spec, &out.Spec, s); err != nil {
return err
}
return Convert_unversioned_PolicyStatus_To_v1alpha1_PolicyStatus(&in.Status, &out.Status, s)
}

//nolint:revive // ignore linter for autogenerated code
func Convert_v1alpha1_Policy_To_unversioned_Policy(in *Policy, out *unversioned.Policy, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.ObjectMeta.Name = "ratify-policy"
if err := Convert_v1alpha1_PolicySpec_To_unversioned_PolicySpec(&in.Spec, &out.Spec, s); err != nil {
return err
}
out.Spec.Type = in.ObjectMeta.Name
return Convert_v1alpha1_PolicyStatus_To_unversioned_PolicyStatus(&in.Status, &out.Status, s)
}
5 changes: 1 addition & 4 deletions api/v1alpha1/policy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ import (
type PolicySpec struct {
// Important: Run "make" to regenerate code after modifying this file

// Type of the polocy
Type string `json:"type,omitempty"`

// +kubebuilder:pruning:PreserveUnknownFields
// Parameters for this policy
Parameters runtime.RawExtension `json:"parameters,omitempty"`
Expand All @@ -44,6 +41,7 @@ type PolicyStatus struct {

// +kubebuilder:object:root=true
// +kubebuilder:resource:scope="Cluster"
// +kubebuilder:deprecatedversion:warning="v1alpha1 of the Policy API has been deprecated. Please migrate to v1beta1."
// Policy is the Schema for the policies API
type Policy struct {
metav1.TypeMeta `json:",inline"`
Expand All @@ -54,7 +52,6 @@ type Policy struct {
}

// +kubebuilder:object:root=true
// +kubebuilder:storageversion
// PolicyList contains a list of Policy
type PolicyList struct {
metav1.TypeMeta `json:",inline"`
Expand Down
80 changes: 41 additions & 39 deletions api/v1alpha1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions api/v1beta1/policy_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Copyright The Ratify Authors.
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 v1beta1

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

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// PolicySpec defines the desired state of Policy
type PolicySpec struct {
// Important: Run "make" to regenerate code after modifying this file

// Type of the policy
Type string `json:"type,omitempty"`

// +kubebuilder:pruning:PreserveUnknownFields
// Parameters for this policy
Parameters runtime.RawExtension `json:"parameters,omitempty"`
}

// PolicyStatus defines the observed state of Policy
type PolicyStatus struct {
// Important: Run "make" to regenerate code after modifying this file

// Is successful while applying the policy.
IsSuccess bool `json:"issuccess"`

// Error message if policy is not successfully applied.
// +optional
Error string `json:"error,omitempty"`
// Truncated error message if the message is too long
// +optional
BriefError string `json:"brieferror,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:resource:scope="Cluster"
// +kubebuilder:subresource:status
// +kubebuilder:storageversion
// +kubebuilder:printcolumn:name="IsSuccess",type=boolean,JSONPath=`.status.issuccess`
// +kubebuilder:printcolumn:name="Error",type=string,JSONPath=`.status.brieferror`
// Policy is the Schema for the policies API
type Policy struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec PolicySpec `json:"spec,omitempty"`
Status PolicyStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:storageversion
// PolicyList contains a list of Policy
type PolicyList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Policy `json:"items"`
}

func init() {
SchemeBuilder.Register(&Policy{}, &PolicyList{})
}
Loading

0 comments on commit c6398a0

Please sign in to comment.