-
Notifications
You must be signed in to change notification settings - Fork 9
/
providers.go
88 lines (74 loc) · 2.95 KB
/
providers.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
/*
* Copyright (C) 2022 Appvia Ltd <info@appvia.io>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fixtures
import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
corev1alpha1 "github.com/appvia/terranetes-controller/pkg/apis/core/v1alpha1"
terraformv1alpha1 "github.com/appvia/terranetes-controller/pkg/apis/terraform/v1alpha1"
"github.com/appvia/terranetes-controller/pkg/controller"
)
// NewValidAWSProvider returns a valid provider for aws
func NewValidAWSProvider(name string, secret *v1.Secret) *terraformv1alpha1.Provider {
provider := &terraformv1alpha1.Provider{
ObjectMeta: metav1.ObjectMeta{Name: name},
Spec: terraformv1alpha1.ProviderSpec{
Source: terraformv1alpha1.SourceSecret,
Provider: "aws",
},
}
if secret != nil {
provider.Spec.SecretRef = &v1.SecretReference{Name: secret.Name, Namespace: secret.Namespace}
}
return provider
}
// NewValidAWSNotReadyProvider returns a ready aws provider
func NewValidAWSNotReadyProvider(name string, secret *v1.Secret) *terraformv1alpha1.Provider {
provider := NewValidAWSProvider(name, secret)
controller.EnsureConditionsRegistered(terraformv1alpha1.DefaultProviderConditions, provider)
provider.Status.GetCondition(corev1alpha1.ConditionReady).Status = metav1.ConditionFalse
return provider
}
// NewValidAWSReadyProvider returns a ready aws provider
func NewValidAWSReadyProvider(name string, secret *v1.Secret) *terraformv1alpha1.Provider {
provider := NewValidAWSProvider(name, secret)
controller.EnsureConditionsRegistered(terraformv1alpha1.DefaultProviderConditions, provider)
provider.Status.GetCondition(corev1alpha1.ConditionReady).Status = metav1.ConditionTrue
return provider
}
// NewAuthenticationSecret returns a valid provider secret for a configuration
func NewAuthenticationSecret(namespace, name string) *v1.Secret {
secret := &v1.Secret{}
secret.Namespace = namespace
secret.Name = name
secret.Data = map[string][]byte{
"GIT_USERNAME": []byte("test"),
"GIT_PASSWORD": []byte("test"),
}
return secret
}
// NewValidAWSProviderSecret returns a valid provider secret for aws
func NewValidAWSProviderSecret(namespace, name string) *v1.Secret {
secret := &v1.Secret{}
secret.Namespace = namespace
secret.Name = name
secret.Data = map[string][]byte{
"AWS_ACCESS_KEY_ID": []byte("test"),
"AWS_SECRET_ACCESS_KEY": []byte("test"),
}
return secret
}