/
integrationtestscenario_conversion.go
109 lines (96 loc) · 3.02 KB
/
integrationtestscenario_conversion.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
Copyright 2023 Red Hat Inc.
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"
"reflect"
"github.com/redhat-appstudio/integration-service/api/v1beta1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)
func (r *IntegrationTestScenario) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
Complete()
}
// Hub marks this type as a conversion hub.
// ConvertTo converts this ITS to the Hub version (v1beta1).
func (src *IntegrationTestScenario) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1beta1.IntegrationTestScenario)
dst.ObjectMeta = src.ObjectMeta
dst.Spec.Application = src.Spec.Application
dst.Status = v1beta1.IntegrationTestScenarioStatus{Conditions: make([]metav1.Condition, 0)}
if !reflect.ValueOf(src.Spec.Environment).IsZero() {
dst.Spec.Environment = v1beta1.TestEnvironment(src.Spec.Environment)
}
if src.Spec.Params != nil {
for _, par := range src.Spec.Params {
dst.Spec.Params = append(dst.Spec.Params, v1beta1.PipelineParameter(par))
}
}
if src.Spec.Contexts != nil {
for _, par := range src.Spec.Contexts {
dst.Spec.Contexts = append(dst.Spec.Contexts, v1beta1.TestContext(par))
}
}
if src.Status.Conditions != nil {
dst.Status.Conditions = append(dst.Status.Conditions, src.Status.Conditions...)
}
dst.Spec.ResolverRef = v1beta1.ResolverRef{
Resolver: "bundles",
Params: []v1beta1.ResolverParameter{
{
Name: "bundle",
Value: src.Spec.Bundle,
},
{
Name: "name",
Value: src.Spec.Pipeline,
},
{
Name: "kind",
Value: "pipeline",
},
},
}
return nil
}
func (dst *IntegrationTestScenario) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1beta1.IntegrationTestScenario)
dst.ObjectMeta = src.ObjectMeta
dst.Spec.Application = src.Spec.Application
if !reflect.ValueOf(dst.Spec.Environment).IsZero() {
dst.Spec.Environment = TestEnvironment(src.Spec.Environment)
}
if src.Spec.Params != nil {
for _, par := range src.Spec.Params {
dst.Spec.Params = append(dst.Spec.Params, PipelineParameter(par))
}
}
if src.Spec.Contexts != nil {
for _, par := range src.Spec.Contexts {
dst.Spec.Contexts = append(dst.Spec.Contexts, TestContext(par))
}
}
if src.Spec.ResolverRef.Resolver == "bundles" {
for _, par := range src.Spec.ResolverRef.Params {
if par.Name == "bundle" {
dst.Spec.Bundle = par.Value
}
if par.Name == "name" {
dst.Spec.Pipeline = par.Value
}
}
}
return nil
}