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

Commit d484b16

Browse files
authored
Merge pull request #12 from rhuss/master
fix: Update to latest sdk version
2 parents 2e329f8 + 4a2e8f3 commit d484b16

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ The first step to leveraging the Operator Lifecycle Manager is to create a manif
126126

127127
For the purpose of this guide, we will continue with this [predefined manifest][manifest_v1] file for the next steps. If you’d like, you can alter the image field within this manifest to reflect the image you built in previous steps, but it is unnecessary. In the future, the Operator SDK CLI will generate an Operator manifest for you, a feature that is planned for the next release of the Operator SDK.
128128

129-
### Deploy the Operator
129+
### Deploy the Operator
130130

131131
Deploying an Operator is as simple as applying the Operator’s manifest to the desired namespace in the cluster.
132132

@@ -140,16 +140,16 @@ After applying this manifest, nothing has happened yet, because the cluster does
140140

141141
```sh
142142
$ kubectl apply -f deploy/rbac.yaml
143-
$ sed '/---/q' deploy/operator.yaml | kubectl apply -f -
143+
$ kubectl apply -f deploy/operator.yaml
144144
```
145145

146-
Because the Operator Lifecycle Manager creates Operators in a particular namespace when a manifest has been applied, administrators can leverage the native Kubernetes RBAC permission model to restrict which users are allowed to install Operators.
146+
Because the Operator Lifecycle Manager creates Operators in a particular namespace when a manifest has been applied, administrators can leverage the native Kubernetes RBAC permission model to restrict which users are allowed to install Operators.
147147

148-
### Create an application instance
148+
### Create an application instance
149149

150-
The Memcached Operator is now running in the `memcached` namespace. Users interact with Operators via instances of CustomResources; in this case, the resource has the Kind `Memcached`. Native Kubernetes RBAC also applies to CustomResources, providing administrators control over who can interact with each Operator.
150+
The Memcached Operator is now running in the `memcached` namespace. Users interact with Operators via instances of CustomResources; in this case, the resource has the Kind `Memcached`. Native Kubernetes RBAC also applies to CustomResources, providing administrators control over who can interact with each Operator.
151151

152-
Creating instances of Memcached in this namespace will now trigger the Memcached Operator to instantiate pods running the memcached server that are managed by the Operator. The more CustomResources you create, the more unique instances of Memcached will be managed by the Memcached Operator running in this namespace.
152+
Creating instances of Memcached in this namespace will now trigger the Memcached Operator to instantiate pods running the memcached server that are managed by the Operator. The more CustomResources you create, the more unique instances of Memcached will be managed by the Memcached Operator running in this namespace.
153153

154154
```sh
155155
$ cat <<EOF | kubectl apply -f -
@@ -183,7 +183,7 @@ memcached-for-wordpress-65b75fd8c9-7b9x7 1/1 Running 0 8s
183183

184184
Manually applying an update to the Operator is as simple as creating a new Operator manifest with a `replaces` field that references the old Operator manifest. The Operator Lifecycle Manager will ensure that all resources being managed by the old Operator have their ownership moved to the new Operator without fear of any programs stopping execution. It is up to the Operators themselves to execute any data migrations required to upgrade resources to run under a new version of the Operator.
185185

186-
The following command demonstrates applying a new [manifest_v2][Operator manifest] using a new version of the Operator and shows that the pods remain executing:
186+
The following command demonstrates applying a new [Operator manifest][manifest_v2] using a new version of the Operator and shows that the pods remain executing:
187187

188188
```sh
189189
$ curl -Lo memcachedoperator.0.0.2.csv.yaml https://raw.githubusercontent.com/operator-framework/getting-started/master/memcachedoperator.0.0.2.csv.yaml

handler.go.tmpl

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,25 @@ import (
44
"fmt"
55
"reflect"
66

7-
v1alpha1 "github.com/example-inc/memcached-operator/pkg/apis/cache/v1alpha1"
7+
"github.com/example-inc/memcached-operator/pkg/apis/cache/v1alpha1"
88

9-
"github.com/operator-framework/operator-sdk/pkg/sdk/action"
10-
"github.com/operator-framework/operator-sdk/pkg/sdk/handler"
11-
"github.com/operator-framework/operator-sdk/pkg/sdk/query"
12-
"github.com/operator-framework/operator-sdk/pkg/sdk/types"
9+
"github.com/operator-framework/operator-sdk/pkg/sdk"
1310
appsv1 "k8s.io/api/apps/v1"
1411
"k8s.io/api/core/v1"
1512
apierrors "k8s.io/apimachinery/pkg/api/errors"
1613
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1714
"k8s.io/apimachinery/pkg/labels"
15+
"context"
1816
)
1917

20-
func NewHandler() handler.Handler {
18+
func NewHandler() sdk.Handler {
2119
return &Handler{}
2220
}
2321

2422
type Handler struct {
2523
}
2624

27-
func (h *Handler) Handle(ctx types.Context, event types.Event) error {
25+
func (h *Handler) Handle(ctx context.Context, event sdk.Event) error {
2826
switch o := event.Object.(type) {
2927
case *v1alpha1.Memcached:
3028
memcached := o
@@ -37,20 +35,20 @@ func (h *Handler) Handle(ctx types.Context, event types.Event) error {
3735

3836
// Create the deployment if it doesn't exist
3937
dep := deploymentForMemcached(memcached)
40-
err := action.Create(dep)
38+
err := sdk.Create(dep)
4139
if err != nil && !apierrors.IsAlreadyExists(err) {
4240
return fmt.Errorf("failed to create deployment: %v", err)
4341
}
4442

4543
// Ensure the deployment size is the same as the spec
46-
err = query.Get(dep)
44+
err = sdk.Get(dep)
4745
if err != nil {
4846
return fmt.Errorf("failed to get deployment: %v", err)
4947
}
5048
size := memcached.Spec.Size
5149
if *dep.Spec.Replicas != size {
5250
dep.Spec.Replicas = &size
53-
err = action.Update(dep)
51+
err = sdk.Update(dep)
5452
if err != nil {
5553
return fmt.Errorf("failed to update deployment: %v", err)
5654
}
@@ -60,14 +58,14 @@ func (h *Handler) Handle(ctx types.Context, event types.Event) error {
6058
podList := podList()
6159
labelSelector := labels.SelectorFromSet(labelsForMemcached(memcached.Name)).String()
6260
listOps := &metav1.ListOptions{LabelSelector: labelSelector}
63-
err = query.List(memcached.Namespace, podList, query.WithListOptions(listOps))
61+
err = sdk.List(memcached.Namespace, podList, sdk.WithListOptions(listOps))
6462
if err != nil {
6563
return fmt.Errorf("failed to list pods: %v", err)
6664
}
6765
podNames := getPodNames(podList.Items)
6866
if !reflect.DeepEqual(podNames, memcached.Status.Nodes) {
6967
memcached.Status.Nodes = podNames
70-
err := action.Update(memcached)
68+
err := sdk.Update(memcached)
7169
if err != nil {
7270
return fmt.Errorf("failed to update memcached status: %v", err)
7371
}
@@ -157,4 +155,4 @@ func getPodNames(pods []v1.Pod) []string {
157155
podNames = append(podNames, pod.Name)
158156
}
159157
return podNames
160-
}
158+
}

0 commit comments

Comments
 (0)