Skip to content

Commit

Permalink
bumped to sdk 1.5 (#12)
Browse files Browse the repository at this point in the history
Signed-off-by: raffaelespazzoli <raffaele.spazzoli@gmail.com>
  • Loading branch information
raffaelespazzoli committed Apr 27, 2021
1 parent 7885c71 commit 71684e5
Show file tree
Hide file tree
Showing 19 changed files with 390 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Download operator sdk
shell: bash
env:
RELEASE_VERSION: v1.3.0
RELEASE_VERSION: v1.5.0
run: |
curl -LO https://github.com/operator-framework/operator-sdk/releases/download/${RELEASE_VERSION}/operator-sdk_linux_amd64
chmod +x operator-sdk_linux_amd64
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Download operator sdk
shell: bash
env:
RELEASE_VERSION: v1.3.0
RELEASE_VERSION: v1.5.0
run: |
curl -LO https://github.com/operator-framework/operator-sdk/releases/download/${RELEASE_VERSION}/operator-sdk_linux_amd64
chmod +x operator-sdk_linux_amd64
Expand Down Expand Up @@ -208,7 +208,7 @@ jobs:
- name: Download operator sdk
shell: bash
env:
RELEASE_VERSION: v1.3.0
RELEASE_VERSION: v1.5.0
run: |
curl -LO https://github.com/operator-framework/operator-sdk/releases/download/${RELEASE_VERSION}/operator-sdk_linux_amd64
chmod +x operator-sdk_linux_amd64
Expand Down
7 changes: 4 additions & 3 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
domain: redhatcop.redhat.io
layout: go.kubebuilder.io/v2
layout: go.kubebuilder.io/v3
projectName: volume-expander-operator
repo: github.com/redhat-cop/volume-expander-operator
version: 3-alpha
version: "3"
plugins:
go.sdk.operatorframework.io/v2-alpha: {}
manifests.sdk.operatorframework.io/v2: {}
scorecard.sdk.operatorframework.io/v2: {}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ helm upgrade volume-expander-operator volume-expander-operator/volume-expander-o
```shell
oc new-project volume-expander-operator-local
kustomize build ./config/local-development | oc apply -f - -n volume-expander-operator-local
export token=export token=$(oc serviceaccounts get-token 'default' -n volume-expander-operator-local)
export token=export token=$(oc serviceaccounts get-token 'volume-expander-operator-manager' -n volume-expander-operator-local)
export base_domain=$(oc get dns cluster -o jsonpath='{.spec.baseDomain}')
export prometheus_route=https://prometheus-k8s-openshift-monitoring.apps.${base_domain}
oc login --token ${token}
Expand All @@ -94,7 +94,7 @@ Define an image and tag. For example...

```shell
export imageRepository="quay.io/redhat-cop/volume-expander-operator"
export imageTag="v0.1.6"
export imageTag="$(git describe --tags --abbrev=0)" # grabs the most recent git tag, which should match the image tag
```

Deploy chart...
Expand Down
1 change: 1 addition & 0 deletions config/helmchart/templates/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ spec:
labels:
{{- include "volume-expander-operator.selectorLabels" . | nindent 8 }}
spec:
serviceAccountName: volume-expander-operator-controller-manager
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
Expand Down
1 change: 1 addition & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ spec:
labels:
control-plane: controller-manager
spec:
serviceAccountName: controller-manager
containers:
- command:
- /manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ metadata:
categories: Storage,Monitoring
certified: "false"
containerImage: quay.io/redhat-cop/volume-expander-operator
operatorframework.io/suggested-namespace: volume-expander-operator
createdAt: 10/14/2020
description: This operator provides automation expanding pod's volumes when they are about to run out of space.
operators.operatorframework.io/builder: operator-sdk-v1.1.0
Expand Down
2 changes: 1 addition & 1 deletion config/rbac/auth_proxy_role_binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ roleRef:
name: proxy-role
subjects:
- kind: ServiceAccount
name: default
name: controller-manager
namespace: system
1 change: 1 addition & 0 deletions config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
resources:
- service_account.yaml
- role.yaml
- role_binding.yaml
- leader_election_role.yaml
Expand Down
2 changes: 1 addition & 1 deletion config/rbac/leader_election_role_binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ roleRef:
name: leader-election-role
subjects:
- kind: ServiceAccount
name: default
name: controller-manager
namespace: system
2 changes: 1 addition & 1 deletion config/rbac/role_binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ roleRef:
name: manager-role
subjects:
- kind: ServiceAccount
name: default
name: controller-manager
namespace: system
5 changes: 5 additions & 0 deletions config/rbac/service_account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: controller-manager
namespace: system
2 changes: 1 addition & 1 deletion config/scorecard/patches/basic.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
entrypoint:
- scorecard-test
- basic-check-spec
image: quay.io/operator-framework/scorecard-test:v1.1.0
image: quay.io/operator-framework/scorecard-test:v1.5.0
labels:
suite: basic
test: basic-check-spec-test
10 changes: 5 additions & 5 deletions config/scorecard/patches/olm.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
entrypoint:
- scorecard-test
- olm-bundle-validation
image: quay.io/operator-framework/scorecard-test:v1.1.0
image: quay.io/operator-framework/scorecard-test:v1.5.0
labels:
suite: olm
test: olm-bundle-validation-test
Expand All @@ -14,7 +14,7 @@
entrypoint:
- scorecard-test
- olm-crds-have-validation
image: quay.io/operator-framework/scorecard-test:v1.1.0
image: quay.io/operator-framework/scorecard-test:v1.5.0
labels:
suite: olm
test: olm-crds-have-validation-test
Expand All @@ -24,7 +24,7 @@
entrypoint:
- scorecard-test
- olm-crds-have-resources
image: quay.io/operator-framework/scorecard-test:v1.1.0
image: quay.io/operator-framework/scorecard-test:v1.5.0
labels:
suite: olm
test: olm-crds-have-resources-test
Expand All @@ -34,7 +34,7 @@
entrypoint:
- scorecard-test
- olm-spec-descriptors
image: quay.io/operator-framework/scorecard-test:v1.1.0
image: quay.io/operator-framework/scorecard-test:v1.5.0
labels:
suite: olm
test: olm-spec-descriptors-test
Expand All @@ -44,7 +44,7 @@
entrypoint:
- scorecard-test
- olm-status-descriptors
image: quay.io/operator-framework/scorecard-test:v1.1.0
image: quay.io/operator-framework/scorecard-test:v1.5.0
labels:
suite: olm
test: olm-status-descriptors-test
23 changes: 11 additions & 12 deletions controllers/persistentvolumeclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ type PersistentVolumeClaimReconciler struct {
// +kubebuilder:rbac:groups=core,resources=pods,verbs=get;list;watch;delete
// +kubebuilder:rbac:groups=core,resources=namespaces,verbs=get

func (r *PersistentVolumeClaimReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
_ = context.Background()
func (r *PersistentVolumeClaimReconciler) Reconcile(context context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := r.Log.WithValues("pvc", req.NamespacedName)

// your logic here
Expand All @@ -85,7 +84,7 @@ func (r *PersistentVolumeClaimReconciler) Reconcile(req ctrl.Request) (ctrl.Resu

// Fetch the GlobalRouteDiscovery instance
instance := &corev1.PersistentVolumeClaim{}
err := r.Get(context.TODO(), req.NamespacedName, instance)
err := r.Get(context, req.NamespacedName, instance)
if err != nil {
if errs.IsNotFound(err) {
// Request object not found, could have been deleted after reconcile request.
Expand All @@ -102,7 +101,7 @@ func (r *PersistentVolumeClaimReconciler) Reconcile(req ctrl.Request) (ctrl.Resu
logger: logger,
}

ok, used, capacity, err := r.pollMetrics(reconcileContext)
ok, used, capacity, err := r.pollMetrics(context, reconcileContext)
if err != nil {
logger.Error(err, "unable to poll metrics for", "pvc", instance)
return r.manageError(err, reconcileContext)
Expand Down Expand Up @@ -133,7 +132,7 @@ func (r *PersistentVolumeClaimReconciler) Reconcile(req ctrl.Request) (ctrl.Resu
logger.V(1).Info("final", "value", newValue)
if newValue.Cmp(reconcileContext.instance.Spec.Resources.Requests[corev1.ResourceStorage]) == 1 {
reconcileContext.instance.Spec.Resources.Requests[corev1.ResourceStorage] = *newValue
err := r.Update(context.TODO(), reconcileContext.instance, &client.UpdateOptions{})
err := r.Update(context, reconcileContext.instance, &client.UpdateOptions{})
if err != nil {
logger.Error(err, "unable to update", "pvc", reconcileContext.instance)
return r.manageError(err, reconcileContext)
Expand All @@ -149,7 +148,7 @@ func (r *PersistentVolumeClaimReconciler) Reconcile(req ctrl.Request) (ctrl.Resu
//we need to kill the attached pods
logger.V(1).Info("we need to kill the attached pods")
podList := &corev1.PodList{}
err := r.List(context.TODO(), podList, &client.ListOptions{
err := r.List(context, podList, &client.ListOptions{
Namespace: reconcileContext.instance.Namespace,
})
if err != nil {
Expand All @@ -159,7 +158,7 @@ func (r *PersistentVolumeClaimReconciler) Reconcile(req ctrl.Request) (ctrl.Resu
toBeKilledPods := filterPods(reconcileContext, podList.Items)
logger.V(1).Info("to be killed pods", "len", len(toBeKilledPods))
for _, pod := range toBeKilledPods {
err := r.Delete(context.TODO(), &pod, &client.DeleteOptions{})
err := r.Delete(context, &pod, &client.DeleteOptions{})
if err != nil {
logger.Error(err, "unable to delete", "pod", pod.Name)
r.manageError(err, reconcileContext)
Expand Down Expand Up @@ -253,11 +252,11 @@ func (r *reconcileContext) getExtendUpTo() *resource.Quantity {
func (r *PersistentVolumeClaimReconciler) SetupWithManager(mgr ctrl.Manager) error {
isAnnotatedPVC := predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
value, _ := e.MetaNew.GetAnnotations()[autoExtendAnnotation]
value, _ := e.ObjectNew.GetAnnotations()[autoExtendAnnotation]
return value == "true"
},
CreateFunc: func(e event.CreateEvent) bool {
value, _ := e.Meta.GetAnnotations()[autoExtendAnnotation]
value, _ := e.Object.GetAnnotations()[autoExtendAnnotation]
return value == "true"
},
DeleteFunc: func(e event.DeleteEvent) bool {
Expand Down Expand Up @@ -291,7 +290,7 @@ func (r *PersistentVolumeClaimReconciler) getOauthToken(reconcileContext *reconc
return string(content)
}

func (r *PersistentVolumeClaimReconciler) pollMetrics(reconcileContext *reconcileContext) (available bool, used int64, capacity int64, err error) {
func (r *PersistentVolumeClaimReconciler) pollMetrics(context context.Context, reconcileContext *reconcileContext) (available bool, used int64, capacity int64, err error) {
address, found := os.LookupEnv(prometheusEnvironmentVariable)
if !found {
address = defaultPrometheusAddress
Expand Down Expand Up @@ -325,7 +324,7 @@ func (r *PersistentVolumeClaimReconciler) pollMetrics(reconcileContext *reconcil
"Authorization": "Bearer " + r.getOauthToken(reconcileContext),
})

resultUsed, warnings, err := papi.Query(context.TODO(), "kubelet_volume_stats_used_bytes{namespace=\""+reconcileContext.instance.Namespace+"\",persistentvolumeclaim=\""+reconcileContext.instance.Name+"\"}", time.Now())
resultUsed, warnings, err := papi.Query(context, "kubelet_volume_stats_used_bytes{namespace=\""+reconcileContext.instance.Namespace+"\",persistentvolumeclaim=\""+reconcileContext.instance.Name+"\"}", time.Now())
if err != nil {
reconcileContext.logger.Error(err, "unable to query for used bytes", "query", "kubelet_volume_stats_used_bytes{namespace=\""+reconcileContext.instance.Namespace+"\",persistentvolumeclaim=\""+reconcileContext.instance.Name+"\"}")
return false, 0, 0, err
Expand Down Expand Up @@ -360,7 +359,7 @@ func (r *PersistentVolumeClaimReconciler) pollMetrics(reconcileContext *reconcil
return false, 0, 0, err
}
}
resultCapacity, warnings, err := papi.Query(context.TODO(), "kubelet_volume_stats_capacity_bytes{namespace=\""+reconcileContext.instance.Namespace+"\",persistentvolumeclaim=\""+reconcileContext.instance.Name+"\"}", time.Now())
resultCapacity, warnings, err := papi.Query(context, "kubelet_volume_stats_capacity_bytes{namespace=\""+reconcileContext.instance.Namespace+"\",persistentvolumeclaim=\""+reconcileContext.instance.Name+"\"}", time.Now())
if err != nil {
reconcileContext.logger.Error(err, "unable to query for capacity bytes", "query", "kubelet_volume_stats_capacity_bytes{namespace=\""+reconcileContext.instance.Namespace+"\",persistentvolumeclaim=\""+reconcileContext.instance.Name+"\"}")
return false, 0, 0, err
Expand Down
2 changes: 1 addition & 1 deletion controllers/prometheusclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ func (h *apiClientImpl) URL(ep string, args map[string]string) *url.URL {
}

func (h *apiClientImpl) Do(ctx context.Context, req *http.Request) (*http.Response, []byte, Warnings, error) {
resp, body, _, err := h.client.Do(ctx, req)
resp, body, err := h.client.Do(ctx, req)
if err != nil {
return resp, body, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
// +kubebuilder:scaffold:imports
)

Expand All @@ -49,7 +49,7 @@ func TestAPIs(t *testing.T) {
}

var _ = BeforeSuite(func(done Done) {
logf.SetLogger(zap.LoggerTo(GinkgoWriter, true))
logf.SetLogger(ctrl.Log.WithName("setup"))

By("bootstrapping test environment")
testEnv = &envtest.Environment{
Expand Down
20 changes: 10 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module github.com/redhat-cop/volume-expander-operator

go 1.13
go 1.15

require (
github.com/go-logr/logr v0.1.0
github.com/go-logr/logr v0.3.0
github.com/json-iterator/go v1.1.10
github.com/onsi/ginkgo v1.12.1
github.com/onsi/gomega v1.10.1
github.com/prometheus/client_golang v1.0.0
github.com/prometheus/common v0.4.1
k8s.io/api v0.18.6
k8s.io/apimachinery v0.18.6
k8s.io/client-go v0.18.6
sigs.k8s.io/controller-runtime v0.6.2
github.com/onsi/ginkgo v1.14.1
github.com/onsi/gomega v1.10.2
github.com/prometheus/client_golang v1.7.1
github.com/prometheus/common v0.10.0
k8s.io/api v0.20.0
k8s.io/apimachinery v0.20.0
k8s.io/client-go v0.20.0
sigs.k8s.io/controller-runtime v0.7.2
)
Loading

0 comments on commit 71684e5

Please sign in to comment.