forked from ratify-project/ratify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add type to policy CRD (ratify-project#1079)
Signed-off-by: Binbin Li <[email protected]>
- Loading branch information
Showing
21 changed files
with
844 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
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" | ||
"github.com/deislabs/ratify/internal/constants" | ||
conversion "k8s.io/apimachinery/pkg/conversion" | ||
) | ||
|
||
// Convert unversioned PolicySpec to PolicySpec of v1alpha1. | ||
// | ||
//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 | ||
} | ||
|
||
// Convert unversioned PolicyStatus to PolicyStatus of v1alpha1. | ||
// | ||
//nolint:revive // ignore linter for autogenerated code | ||
func Convert_unversioned_PolicyStatus_To_v1alpha1_PolicyStatus(in *unversioned.PolicyStatus, out *PolicyStatus, _ conversion.Scope) error { | ||
return nil | ||
} | ||
|
||
// Convert unversioned Policy to Policy of v1alpha1. | ||
// | ||
//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 | ||
// metadata.name in v1alpha1 is same as spec.type in unversioned. | ||
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) | ||
} | ||
|
||
// Convert Policy of v1alpha1 to unversioned Policy. | ||
// | ||
//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 | ||
// metadata.name MUST be `ratify-policy` in unversioned. | ||
out.ObjectMeta.Name = constants.RatifyPolicy | ||
if err := Convert_v1alpha1_PolicySpec_To_unversioned_PolicySpec(&in.Spec, &out.Spec, s); err != nil { | ||
return err | ||
} | ||
// spec.type in unversioned is same as metadata.name in v1alpha1. | ||
out.Spec.Type = in.ObjectMeta.Name | ||
return Convert_v1alpha1_PolicyStatus_To_unversioned_PolicyStatus(&in.Status, &out.Status, s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
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 ( | ||
"reflect" | ||
"testing" | ||
|
||
unversioned "github.com/deislabs/ratify/api/unversioned" | ||
"github.com/deislabs/ratify/internal/constants" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
runtime "k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
var params = runtime.RawExtension{} | ||
|
||
const testPolicyType = "testPolicyType" | ||
|
||
func TestConvert_unversioned_PolicySpec_To_v1alpha1_PolicySpec(t *testing.T) { | ||
in := &unversioned.PolicySpec{ | ||
Parameters: params, | ||
} | ||
out := &PolicySpec{} | ||
if err := Convert_unversioned_PolicySpec_To_v1alpha1_PolicySpec(in, out, nil); err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
if !reflect.DeepEqual(out.Parameters, in.Parameters) { | ||
t.Fatalf("expect parameters to be equal, but got different values") | ||
} | ||
} | ||
|
||
func TestConvert_unversioned_PolicyStatus_To_v1alpha1_PolicyStatus(t *testing.T) { | ||
if err := Convert_unversioned_PolicyStatus_To_v1alpha1_PolicyStatus(nil, nil, nil); err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
} | ||
|
||
func TestConvert_unversioned_Policy_To_v1alpha1_Policy(t *testing.T) { | ||
in := &unversioned.Policy{ | ||
Spec: unversioned.PolicySpec{ | ||
Type: testPolicyType, | ||
}, | ||
} | ||
out := &Policy{} | ||
if err := Convert_unversioned_Policy_To_v1alpha1_Policy(in, out, nil); err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
if out.ObjectMeta.Name != in.Spec.Type { | ||
t.Fatalf("expect metadata.name to be %s, but got %s", in.Spec.Type, out.ObjectMeta.Name) | ||
} | ||
} | ||
|
||
func TestConvert_v1alpha1_Policy_To_unversioned_Policy(t *testing.T) { | ||
in := &Policy{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: testPolicyType, | ||
}, | ||
} | ||
out := &unversioned.Policy{} | ||
if err := Convert_v1alpha1_Policy_To_unversioned_Policy(in, out, nil); err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
if out.ObjectMeta.Name != constants.RatifyPolicy { | ||
t.Fatalf("expect metadata.name to be %s, but got %s", constants.RatifyPolicy, out.ObjectMeta.Name) | ||
} | ||
if out.Spec.Type != in.ObjectMeta.Name { | ||
t.Fatalf("expect spec.type to be %s, but got %s", in.ObjectMeta.Name, out.Spec.Type) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.