Skip to content
This repository was archived by the owner on Nov 18, 2020. It is now read-only.

Commit 18984e7

Browse files
authored
vault-operator/*: sync with operator-sdk master (#28)
This commit updates the vault-operator to work with the master version of the operator-sdk. This makes the example a better representation of the current state of the operator-sdk and also allows us to add e2e tests using the sdk's test framework.
1 parent 851f50d commit 18984e7

File tree

13 files changed

+301
-158
lines changed

13 files changed

+301
-158
lines changed

vault-operator/Gopkg.lock

Lines changed: 191 additions & 112 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vault-operator/Gopkg.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[[override]]
22
name = "k8s.io/api"
3-
version = "kubernetes-1.9.3"
3+
version = "kubernetes-1.10.1"
44

55
[[override]]
66
name = "k8s.io/apimachinery"
7-
version = "kubernetes-1.9.3"
7+
version = "kubernetes-1.10.1"
88

99
[[override]]
1010
name = "k8s.io/client-go"
11-
version = "kubernetes-1.9.3"
11+
version = "kubernetes-1.10.1"
1212

1313
[[override]]
1414
# TODO: use version instead of branch
@@ -18,5 +18,5 @@
1818
[[constraint]]
1919
name = "github.com/operator-framework/operator-sdk"
2020
# The version rule is used for a specific release and the master branch for in between releases.
21-
# branch = "master"
22-
version = "=v0.0.5"
21+
branch = "master"
22+
# version ="v0.0.5"

vault-operator/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The quick start guide walks through the process of building the Vault operator i
1010

1111
### Prerequisites
1212

13-
- [dep][dep_tool] version v0.4.1+.
13+
- [dep][dep_tool] version v0.5.0+.
1414
- [go][go_tool] version v1.10+.
1515
- [docker][docker_tool] version 17.03+.
1616
- [kubectl][kubectl_tool] version v1.9.0+.
@@ -24,7 +24,7 @@ First, checkout and install the operator-sdk CLI:
2424

2525
```sh
2626
$ cd $GOPATH/src/github.com/operator-framework/operator-sdk
27-
$ git checkout tags/v0.0.5
27+
$ git checkout master
2828
$ dep ensure
2929
$ go install github.com/operator-framework/operator-sdk/commands/operator-sdk
3030
```
@@ -68,6 +68,12 @@ Deploy the etcd-operator first because the Vault operator depends on it for prov
6868
$ kubectl create -f deploy/etcd-operator.yaml
6969
```
7070

71+
Deploy the Vault CRD:
72+
73+
```sh
74+
$ kubectl create -f deploy/crd.yaml
75+
```
76+
7177
Deploy the Vault operator:
7278

7379
```sh

vault-operator/deploy/crd.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: vaultservices.vault.security.coreos.com
5+
spec:
6+
group: vault.security.coreos.com
7+
names:
8+
kind: VaultService
9+
listKind: VaultServiceList
10+
plural: vaultservices
11+
singular: vaultservice
12+
scope: Namespaced
13+
version: v1alpha1

vault-operator/pkg/apis/vault/v1alpha1/zz_generated.deepcopy.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,47 @@ func (in *PodPolicy) DeepCopy() *PodPolicy {
2525
return out
2626
}
2727

28+
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
29+
func (in *StaticTLS) DeepCopyInto(out *StaticTLS) {
30+
*out = *in
31+
return
32+
}
33+
34+
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StaticTLS.
35+
func (in *StaticTLS) DeepCopy() *StaticTLS {
36+
if in == nil {
37+
return nil
38+
}
39+
out := new(StaticTLS)
40+
in.DeepCopyInto(out)
41+
return out
42+
}
43+
44+
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
45+
func (in *TLSPolicy) DeepCopyInto(out *TLSPolicy) {
46+
*out = *in
47+
if in.Static != nil {
48+
in, out := &in.Static, &out.Static
49+
if *in == nil {
50+
*out = nil
51+
} else {
52+
*out = new(StaticTLS)
53+
**out = **in
54+
}
55+
}
56+
return
57+
}
58+
59+
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TLSPolicy.
60+
func (in *TLSPolicy) DeepCopy() *TLSPolicy {
61+
if in == nil {
62+
return nil
63+
}
64+
out := new(TLSPolicy)
65+
in.DeepCopyInto(out)
66+
return out
67+
}
68+
2869
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
2970
func (in *VaultService) DeepCopyInto(out *VaultService) {
3071
*out = *in
@@ -100,6 +141,15 @@ func (in *VaultServiceSpec) DeepCopyInto(out *VaultServiceSpec) {
100141
(*in).DeepCopyInto(*out)
101142
}
102143
}
144+
if in.TLS != nil {
145+
in, out := &in.TLS, &out.TLS
146+
if *in == nil {
147+
*out = nil
148+
} else {
149+
*out = new(TLSPolicy)
150+
(*in).DeepCopyInto(*out)
151+
}
152+
}
103153
return
104154
}
105155

vault-operator/pkg/stub/handler.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
package stub
22

33
import (
4+
"context"
5+
46
api "github.com/operator-framework/operator-sdk-samples/vault-operator/pkg/apis/vault/v1alpha1"
57
"github.com/operator-framework/operator-sdk-samples/vault-operator/pkg/vault"
6-
7-
"github.com/operator-framework/operator-sdk/pkg/sdk/handler"
8-
"github.com/operator-framework/operator-sdk/pkg/sdk/types"
8+
"github.com/operator-framework/operator-sdk/pkg/sdk"
99
)
1010

11-
func NewHandler() handler.Handler {
11+
func NewHandler() sdk.Handler {
1212
return &Handler{}
1313
}
1414

1515
type Handler struct {
1616
// Fill me
1717
}
1818

19-
func (h *Handler) Handle(ctx types.Context, event types.Event) error {
19+
func (h *Handler) Handle(ctx context.Context, event sdk.Event) error {
2020
switch o := event.Object.(type) {
2121
case *api.VaultService:
2222
return vault.Reconcile(o)

vault-operator/pkg/vault/deploy_etcd.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import (
44
"fmt"
55

66
api "github.com/operator-framework/operator-sdk-samples/vault-operator/pkg/apis/vault/v1alpha1"
7+
"github.com/operator-framework/operator-sdk/pkg/sdk"
78

89
eopapi "github.com/coreos/etcd-operator/pkg/apis/etcd/v1beta2"
9-
"github.com/operator-framework/operator-sdk/pkg/sdk/action"
10-
"github.com/operator-framework/operator-sdk/pkg/sdk/query"
1110
"k8s.io/api/core/v1"
1211
apierrors "k8s.io/apimachinery/pkg/api/errors"
1312
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -52,7 +51,7 @@ func deployEtcdCluster(v *api.VaultService) (*eopapi.EtcdCluster, error) {
5251
ec.Spec.Pod.Resources = v.Spec.Pod.Resources
5352
}
5453
addOwnerRefToObject(ec, asOwner(v))
55-
err := action.Create(ec)
54+
err := sdk.Create(ec)
5655
if err != nil {
5756
if apierrors.IsAlreadyExists(err) {
5857
return ec, nil
@@ -73,7 +72,7 @@ func etcdURLForVault(name string) string {
7372
}
7473

7574
func isEtcdClusterReady(ec *eopapi.EtcdCluster) (bool, error) {
76-
err := query.Get(ec)
75+
err := sdk.Get(ec)
7776
if err != nil {
7877
return false, err
7978
}

vault-operator/pkg/vault/deploy_vault.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"path/filepath"
66

77
api "github.com/operator-framework/operator-sdk-samples/vault-operator/pkg/apis/vault/v1alpha1"
8+
"github.com/operator-framework/operator-sdk/pkg/sdk"
89

9-
"github.com/operator-framework/operator-sdk/pkg/sdk/action"
1010
appsv1 "k8s.io/api/apps/v1"
1111
"k8s.io/api/core/v1"
1212
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -95,7 +95,7 @@ func deployVault(v *api.VaultService) error {
9595
},
9696
}
9797
addOwnerRefToObject(d, asOwner(v))
98-
err := action.Create(d)
98+
err := sdk.Create(d)
9999
if err != nil && !apierrors.IsAlreadyExists(err) {
100100
return err
101101
}
@@ -132,7 +132,7 @@ func deployVault(v *api.VaultService) error {
132132
},
133133
}
134134
addOwnerRefToObject(svc, asOwner(v))
135-
err = action.Create(svc)
135+
err = sdk.Create(svc)
136136
if err != nil && !apierrors.IsAlreadyExists(err) {
137137
return fmt.Errorf("failed to create vault service: %v", err)
138138
}

vault-operator/pkg/vault/reconcile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"fmt"
55

66
api "github.com/operator-framework/operator-sdk-samples/vault-operator/pkg/apis/vault/v1alpha1"
7+
"github.com/operator-framework/operator-sdk/pkg/sdk"
78

8-
"github.com/operator-framework/operator-sdk/pkg/sdk/action"
99
"github.com/sirupsen/logrus"
1010
)
1111

@@ -17,7 +17,7 @@ func Reconcile(vr *api.VaultService) (err error) {
1717
// Simulate initializer.
1818
changed := vr.SetDefaults()
1919
if changed {
20-
return action.Update(vr)
20+
return sdk.Update(vr)
2121
}
2222
// After first time reconcile, phase will switch to "Running".
2323
if vr.Status.Phase == api.ClusterPhaseInitial {

vault-operator/pkg/vault/sync_vault.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import (
66

77
api "github.com/operator-framework/operator-sdk-samples/vault-operator/pkg/apis/vault/v1alpha1"
88

9-
"github.com/operator-framework/operator-sdk/pkg/sdk/action"
10-
"github.com/operator-framework/operator-sdk/pkg/sdk/query"
9+
"github.com/operator-framework/operator-sdk/pkg/sdk"
1110
appsv1 "k8s.io/api/apps/v1"
1211
"k8s.io/api/core/v1"
1312
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -27,14 +26,14 @@ func syncVaultClusterSize(vr *api.VaultService) error {
2726
Namespace: vr.GetNamespace(),
2827
},
2928
}
30-
err := query.Get(d)
29+
err := sdk.Get(d)
3130
if err != nil {
3231
return fmt.Errorf("failed to get deployment (%s): %v", d.Name, err)
3332
}
3433

3534
if *d.Spec.Replicas != vr.Spec.Nodes {
3635
d.Spec.Replicas = &(vr.Spec.Nodes)
37-
err = action.Update(d)
36+
err = sdk.Update(d)
3837
if err != nil {
3938
return fmt.Errorf("failed to update size of deployment (%s): %v", d.Name, err)
4039
}
@@ -59,7 +58,7 @@ func syncUpgrade(vr *api.VaultService, status *api.VaultServiceStatus) (err erro
5958
Namespace: vr.GetNamespace(),
6059
},
6160
}
62-
err = query.Get(d)
61+
err = sdk.Get(d)
6362
if err != nil {
6463
return fmt.Errorf("failed to get deployment (%s): %v", d.Name, err)
6564
}
@@ -114,7 +113,7 @@ func syncUpgrade(vr *api.VaultService, status *api.VaultServiceStatus) (err erro
114113
Namespace: vr.GetNamespace(),
115114
},
116115
}
117-
err = action.Delete(p)
116+
err = sdk.Delete(p)
118117
if err != nil && !apierrors.IsNotFound(err) {
119118
return fmt.Errorf("step down: failed to delete active Vault pod (%s): %v", active, err)
120119
}
@@ -129,7 +128,7 @@ func upgradeDeployment(vr *api.VaultService, d *appsv1.Deployment) error {
129128
mu := intstr.FromInt(int(vr.Spec.Nodes - 1))
130129
d.Spec.Strategy.RollingUpdate.MaxUnavailable = &mu
131130
d.Spec.Template.Spec.Containers[0].Image = vaultImage(vr.Spec)
132-
err := action.Update(d)
131+
err := sdk.Update(d)
133132
if err != nil {
134133
return fmt.Errorf("failed to upgrade deployment to (%s): %v", vaultImage(vr.Spec), err)
135134
}

vault-operator/pkg/vault/tls.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import (
77

88
api "github.com/operator-framework/operator-sdk-samples/vault-operator/pkg/apis/vault/v1alpha1"
99
"github.com/operator-framework/operator-sdk-samples/vault-operator/pkg/tls"
10+
"github.com/operator-framework/operator-sdk/pkg/sdk"
1011

11-
"github.com/operator-framework/operator-sdk/pkg/sdk/action"
12-
"github.com/operator-framework/operator-sdk/pkg/sdk/query"
1312
"k8s.io/api/core/v1"
1413
apierrors "k8s.io/apimachinery/pkg/api/errors"
1514
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -41,7 +40,7 @@ func prepareDefaultVaultTLSSecrets(vr *api.VaultService) (err error) {
4140
Namespace: vr.Namespace,
4241
},
4342
}
44-
err = query.Get(se)
43+
err = sdk.Get(se)
4544
if err == nil {
4645
return nil
4746
}
@@ -59,14 +58,14 @@ func prepareDefaultVaultTLSSecrets(vr *api.VaultService) (err error) {
5958
return err
6059
}
6160
addOwnerRefToObject(se, asOwner(vr))
62-
err = action.Create(se)
61+
err = sdk.Create(se)
6362
if err != nil && !apierrors.IsAlreadyExists(err) {
6463
return err
6564
}
6665

6766
se = newVaultClientTLSSecret(vr, caCrt)
6867
addOwnerRefToObject(se, asOwner(vr))
69-
err = action.Create(se)
68+
err = sdk.Create(se)
7069
if err != nil && !apierrors.IsAlreadyExists(err) {
7170
return err
7271
}
@@ -128,7 +127,7 @@ func prepareEtcdTLSSecrets(vr *api.VaultService) (err error) {
128127
},
129128
}
130129

131-
err = query.Get(se)
130+
err = sdk.Get(se)
132131
if err == nil {
133132
return nil
134133
}
@@ -146,7 +145,7 @@ func prepareEtcdTLSSecrets(vr *api.VaultService) (err error) {
146145
return err
147146
}
148147
addOwnerRefToObject(se, asOwner(vr))
149-
err = action.Create(se)
148+
err = sdk.Create(se)
150149
if err != nil && !apierrors.IsAlreadyExists(err) {
151150
return err
152151
}
@@ -156,7 +155,7 @@ func prepareEtcdTLSSecrets(vr *api.VaultService) (err error) {
156155
return err
157156
}
158157
addOwnerRefToObject(se, asOwner(vr))
159-
err = action.Create(se)
158+
err = sdk.Create(se)
160159
if err != nil && !apierrors.IsAlreadyExists(err) {
161160
return err
162161
}
@@ -166,7 +165,7 @@ func prepareEtcdTLSSecrets(vr *api.VaultService) (err error) {
166165
return err
167166
}
168167
addOwnerRefToObject(se, asOwner(vr))
169-
err = action.Create(se)
168+
err = sdk.Create(se)
170169
if err != nil && !apierrors.IsAlreadyExists(err) {
171170
return err
172171
}

vault-operator/pkg/vault/vault_config.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import (
55
"fmt"
66
"path/filepath"
77

8-
"github.com/operator-framework/operator-sdk/pkg/sdk/action"
9-
"github.com/operator-framework/operator-sdk/pkg/sdk/query"
108
api "github.com/operator-framework/operator-sdk-samples/vault-operator/pkg/apis/vault/v1alpha1"
9+
"github.com/operator-framework/operator-sdk/pkg/sdk"
1110
"k8s.io/api/core/v1"
1211
apierrors "k8s.io/apimachinery/pkg/api/errors"
1312
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -41,7 +40,7 @@ func prepareVaultConfig(vr *api.VaultService) error {
4140
}
4241
if len(vr.Spec.ConfigMapName) != 0 {
4342
cm.Name = vr.Spec.ConfigMapName
44-
err := query.Get(cm)
43+
err := sdk.Get(cm)
4544
if err != nil {
4645
return fmt.Errorf("prepare vault config error: get configmap (%s) failed: %v", vr.Spec.ConfigMapName, err)
4746
}
@@ -54,7 +53,7 @@ func prepareVaultConfig(vr *api.VaultService) error {
5453
cfgData = newConfigWithEtcd(cfgData, etcdURLForVault(vr.Name))
5554
cm.Data = map[string]string{filepath.Base(vaultConfigPath): cfgData}
5655
addOwnerRefToObject(cm, asOwner(vr))
57-
err := action.Create(cm)
56+
err := sdk.Create(cm)
5857
if err != nil && !apierrors.IsAlreadyExists(err) {
5958
return fmt.Errorf("prepare vault config error: create new configmap (%s) failed: %v", cm.Name, err)
6059
}

0 commit comments

Comments
 (0)