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

Commit b4f41e0

Browse files
fix samples update (#165)
1 parent 08e1215 commit b4f41e0

19 files changed

+870
-173
lines changed

.generate/gen-all.sh

100644100755
File mode changed.

go/memcached-operator/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
1111
endif
1212
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
1313

14-
.PHONY: bundle
15-
1614
# Image URL to use all building/pushing image targets
1715
IMG ?= controller:latest
1816
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
@@ -29,8 +27,11 @@ all: manager
2927

3028
# Run tests
3129
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
30+
ENVTEST_ASSETS_DIR = $(shell pwd)/testbin
3231
test: generate fmt vet manifests
33-
mkdir -p ${ENVTEST_ASSETS_DIR}
32+
mkdir -p $(ENVTEST_ASSETS_DIR)
33+
test -f $(ENVTEST_ASSETS_DIR)/setup-envtest.sh || curl -sSLo $(ENVTEST_ASSETS_DIR)/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.6.3/hack/setup-envtest.sh
34+
source $(ENVTEST_ASSETS_DIR)/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); mkdir -p ${ENVTEST_ASSETS_DIR}
3435
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/master/hack/setup-envtest.sh
3536
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
3637

@@ -112,13 +113,15 @@ KUSTOMIZE=$(shell which kustomize)
112113
endif
113114

114115
# Generate bundle manifests and metadata, then validate generated files.
116+
.PHONY: bundle
115117
bundle: manifests
116118
operator-sdk generate kustomize manifests --interactive=false -q
117119
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
118120
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
119121
operator-sdk bundle validate ./bundle
120122

121123
# Build the bundle image.
124+
.PHONY: bundle-build
122125
bundle-build:
123126
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
124127

go/memcached-operator/api/v1alpha1/memcached_types.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ type MemcachedSpec struct {
2828
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
2929
// Important: Run "make" to regenerate code after modifying this file
3030

31-
32-
Size int32 `json:"size"`
31+
Size int32 `json:"size"`
3332
}
3433

3534
// MemcachedStatus defines the observed state of Memcached
3635
type MemcachedStatus struct {
37-
Nodes []string `json:"nodes"`
36+
Nodes []string `json:"nodes"`
3837
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
3938
// Important: Run "make" to regenerate code after modifying this file
4039
}

go/memcached-operator/api/v1alpha1/memcached_webhook.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20-
"errors"
20+
"errors"
2121
"k8s.io/apimachinery/pkg/runtime"
2222
ctrl "sigs.k8s.io/controller-runtime"
2323
logf "sigs.k8s.io/controller-runtime/pkg/log"
@@ -43,8 +43,8 @@ var _ webhook.Defaulter = &Memcached{}
4343
func (r *Memcached) Default() {
4444
memcachedlog.Info("default", "name", r.Name)
4545

46-
if r.Spec.Size == 0 {
47-
r.Spec.Size = 3
46+
if r.Spec.Size == 0 {
47+
r.Spec.Size = 3
4848
}
4949
}
5050

@@ -57,25 +57,25 @@ var _ webhook.Validator = &Memcached{}
5757
func (r *Memcached) ValidateCreate() error {
5858
memcachedlog.Info("validate create", "name", r.Name)
5959

60-
return validateOdd(r.Spec.Size)
60+
return validateOdd(r.Spec.Size)
6161
}
6262

6363
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
6464
func (r *Memcached) ValidateUpdate(old runtime.Object) error {
6565
memcachedlog.Info("validate update", "name", r.Name)
6666

67-
return validateOdd(r.Spec.Size)
67+
return validateOdd(r.Spec.Size)
6868
}
6969

7070
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
7171
func (r *Memcached) ValidateDelete() error {
7272
memcachedlog.Info("validate delete", "name", r.Name)
7373

74-
return nil
74+
return nil
75+
}
76+
func validateOdd(n int32) error {
77+
if n%2 == 0 {
78+
return errors.New("Cluster size must be an odd number")
79+
}
80+
return nil
7581
}
76-
func validateOdd(n int32) error {
77-
if n%2 == 0 {
78-
return errors.New("Cluster size must be an odd number")
79-
}
80-
return nil
81-
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM scratch
2+
3+
LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1
4+
LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
5+
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
6+
LABEL operators.operatorframework.io.bundle.package.v1=memcached-operator
7+
LABEL operators.operatorframework.io.bundle.channels.v1=alpha
8+
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.1.0
9+
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
10+
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v2
11+
LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/
12+
LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1
13+
COPY bundle/manifests /manifests/
14+
COPY bundle/metadata /metadata/
15+
COPY bundle/tests/scorecard /tests/scorecard/
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
annotations:
5+
controller-gen.kubebuilder.io/version: v0.3.0
6+
creationTimestamp: null
7+
name: memcacheds.cache.example.com
8+
spec:
9+
group: cache.example.com
10+
names:
11+
kind: Memcached
12+
listKind: MemcachedList
13+
plural: memcacheds
14+
singular: memcached
15+
scope: Namespaced
16+
subresources:
17+
status: {}
18+
validation:
19+
openAPIV3Schema:
20+
description: Memcached is the Schema for the memcacheds API
21+
properties:
22+
apiVersion:
23+
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
24+
type: string
25+
kind:
26+
description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
27+
type: string
28+
metadata:
29+
type: object
30+
spec:
31+
description: MemcachedSpec defines the desired state of Memcached
32+
properties:
33+
size:
34+
format: int32
35+
type: integer
36+
required:
37+
- size
38+
type: object
39+
status:
40+
description: MemcachedStatus defines the observed state of Memcached
41+
properties:
42+
nodes:
43+
items:
44+
type: string
45+
type: array
46+
required:
47+
- nodes
48+
type: object
49+
type: object
50+
version: v1alpha1
51+
versions:
52+
- name: v1alpha1
53+
served: true
54+
storage: true
55+
status:
56+
acceptedNames:
57+
kind: ""
58+
plural: ""
59+
conditions: []
60+
storedVersions: []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: rbac.authorization.k8s.io/v1beta1
2+
kind: ClusterRole
3+
metadata:
4+
creationTimestamp: null
5+
name: memcached-operator-metrics-reader
6+
rules:
7+
- nonResourceURLs:
8+
- /metrics
9+
verbs:
10+
- get

0 commit comments

Comments
 (0)