From f3acaa55214712b5913036dd0a8a6f5eb94ab894 Mon Sep 17 00:00:00 2001 From: Wagner Sartori Junior Date: Thu, 16 Nov 2023 05:43:43 +0100 Subject: [PATCH 1/7] fix(helm): Possibility to override zfs encryption keys directory (#487) Helm charts was hardcoding zfs encryption keys directory and on some distributions /home is read-only. This commit will make it possible to set it as a helm value. Fixes #477 Signed-off-by: Wagner Sartori Junior --- changelogs/unreleased/487-trunet.md | 1 + deploy/helm/charts/Chart.yaml | 2 +- deploy/helm/charts/README.md | 1 + deploy/helm/charts/templates/zfs-node.yaml | 2 +- deploy/helm/charts/values.yaml | 1 + 5 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/487-trunet.md diff --git a/changelogs/unreleased/487-trunet.md b/changelogs/unreleased/487-trunet.md new file mode 100644 index 000000000..2da45404e --- /dev/null +++ b/changelogs/unreleased/487-trunet.md @@ -0,0 +1 @@ +fix(helm): Possibility to override zfs encryption keys directory \ No newline at end of file diff --git a/deploy/helm/charts/Chart.yaml b/deploy/helm/charts/Chart.yaml index 4696c26f0..20d0fdc14 100644 --- a/deploy/helm/charts/Chart.yaml +++ b/deploy/helm/charts/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 name: zfs-localpv description: Helm chart for CSI Driver for dynamic provisioning of ZFS Persistent Local Volumes. For instructions on how to use this helm chart, see - https://openebs.github.io/zfs-localpv/ -version: 2.3.1 +version: 2.3.2 appVersion: 2.3.0 icon: https://raw.githubusercontent.com/cncf/artwork/master/projects/openebs/icon/color/openebs-icon-color.png home: https://openebs.io/ diff --git a/deploy/helm/charts/README.md b/deploy/helm/charts/README.md index d30f55026..038ab71b2 100644 --- a/deploy/helm/charts/README.md +++ b/deploy/helm/charts/README.md @@ -86,6 +86,7 @@ The following table lists the configurable parameters of the OpenEBS ZFS Localpv | `zfsNode.driverRegistrar.image.tag`| Image tag for csi-node-driver-registrar| `v2.8.0`| | `zfsNode.updateStrategy.type`| Update strategy for zfsnode daemonset | `RollingUpdate` | | `zfsNode.kubeletDir`| Kubelet mount point for zfsnode daemonset| `"/var/lib/kubelet/"` | +| `zfsNode.encrKeysDir` | Zfs encryption key directory| `"/home/keys"` | | `zfsNode.annotations` | Annotations for zfsnode daemonset metadata| `""`| | `zfsNode.podAnnotations`| Annotations for zfsnode daemonset's pods metadata | `""`| | `zfsNode.resources`| Resource and request and limit for zfsnode daemonset containers | `""`| diff --git a/deploy/helm/charts/templates/zfs-node.yaml b/deploy/helm/charts/templates/zfs-node.yaml index 58762c8b7..74859dd7a 100644 --- a/deploy/helm/charts/templates/zfs-node.yaml +++ b/deploy/helm/charts/templates/zfs-node.yaml @@ -118,7 +118,7 @@ spec: type: Directory - name: encr-keys hostPath: - path: /home/keys + path: {{ .Values.zfsNode.encrKeysDir }} type: DirectoryOrCreate - name: chroot-zfs configMap: diff --git a/deploy/helm/charts/values.yaml b/deploy/helm/charts/values.yaml index ae0e21dfe..8bf2f9156 100644 --- a/deploy/helm/charts/values.yaml +++ b/deploy/helm/charts/values.yaml @@ -38,6 +38,7 @@ zfsNode: # This can be configured to run on various different k8s distributions like # microk8s where kubelet dir is different kubeletDir: "/var/lib/kubelet/" + encrKeysDir: "/home/keys" # limits: # cpu: 10m # memory: 32Mi From 4fc31889e75268465c1d6211c2dfd6e60c75c05b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 25 Oct 2023 22:38:17 +0000 Subject: [PATCH 2/7] chore(deps): bump google.golang.org/grpc from 1.55.0 to 1.56.3 Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.55.0 to 1.56.3. - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](https://github.com/grpc/grpc-go/compare/v1.55.0...v1.56.3) --- updated-dependencies: - dependency-name: google.golang.org/grpc dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index eb02bfbf9..b5f350aee 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/stretchr/testify v1.8.1 golang.org/x/net v0.17.0 golang.org/x/sys v0.13.0 - google.golang.org/grpc v1.55.0 + google.golang.org/grpc v1.56.3 google.golang.org/protobuf v1.30.0 k8s.io/api v0.27.2 k8s.io/apimachinery v0.27.2 @@ -63,7 +63,7 @@ require ( golang.org/x/time v0.3.0 // indirect golang.org/x/tools v0.9.1 // indirect google.golang.org/appengine v1.6.7 // indirect - google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect + google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index d4074f313..aaf6eabae 100644 --- a/go.sum +++ b/go.sum @@ -714,8 +714,8 @@ google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20201019141844-1ed22bb0c154/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368/go.mod h1:5CzLGKJ67TSI2B9POpiiyGha0AjJvZIUgRMt1dSmuhc= -google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 h1:DdoeryqhaXp1LtT/emMP1BRJPHHKFi5akj/nbx/zNTA= -google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4/go.mod h1:NWraEVixdDnqcqQ30jipen1STv2r/n24Wb7twVTGR4s= +google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 h1:KpwkzHKEF7B9Zxg18WzOa7djJ+Ha5DzthMyZYQfEn2A= +google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -732,8 +732,8 @@ google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= -google.golang.org/grpc v1.55.0 h1:3Oj82/tFSCeUrRTg/5E/7d/W5A1tj6Ky1ABAuZuv5ag= -google.golang.org/grpc v1.55.0/go.mod h1:iYEXKGkEBhg1PjZQvoYEVPTDkHo1/bjTnfwTeGONTY8= +google.golang.org/grpc v1.56.3 h1:8I4C0Yq1EjstUzUJzpcRVbuYA2mODtEmpWiQoN/b2nc= +google.golang.org/grpc v1.56.3/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= From 1c8cc4151eb485f1c4a5c8133d5b6216bf7db0d6 Mon Sep 17 00:00:00 2001 From: Abhinandan Purkait Date: Fri, 17 Nov 2023 21:44:49 +0530 Subject: [PATCH 3/7] feat(event): update ua to ga4 analytics (#490) * feat(event): update ua to ga4 analytics Signed-off-by: Abhinandan Purkait * feat(google-analytics-4): remove the usage and use common usage Signed-off-by: Abhinandan Purkait * feat(controller): add doc comment for Ping constant Signed-off-by: Abhinandan Purkait --------- Signed-off-by: Abhinandan Purkait --- go.mod | 6 +- go.sum | 12 +- pkg/driver/controller.go | 33 +++-- pkg/usage/const.go | 54 ------- pkg/usage/googleanalytics.go | 54 ------- pkg/usage/ping.go | 66 --------- pkg/usage/ping_test.go | 56 -------- pkg/usage/size.go | 27 ---- pkg/usage/size_test.go | 61 -------- pkg/usage/usage.go | 267 ----------------------------------- pkg/usage/versionset.go | 130 ----------------- 11 files changed, 31 insertions(+), 735 deletions(-) delete mode 100644 pkg/usage/const.go delete mode 100644 pkg/usage/googleanalytics.go delete mode 100644 pkg/usage/ping.go delete mode 100644 pkg/usage/ping_test.go delete mode 100644 pkg/usage/size.go delete mode 100644 pkg/usage/size_test.go delete mode 100644 pkg/usage/usage.go delete mode 100644 pkg/usage/versionset.go diff --git a/go.mod b/go.mod index b5f350aee..da0acd619 100644 --- a/go.mod +++ b/go.mod @@ -4,12 +4,11 @@ go 1.19 require ( github.com/container-storage-interface/spec v1.8.0 - github.com/docker/go-units v0.4.0 - github.com/jpillora/go-ogle-analytics v0.0.0-20161213085824-14b04e0594ef github.com/kubernetes-csi/csi-lib-utils v0.9.0 github.com/onsi/ginkgo v1.16.5 github.com/onsi/gomega v1.27.7 - github.com/openebs/lib-csi v0.8.0 + github.com/openebs/google-analytics-4 v0.1.0 + github.com/openebs/lib-csi v0.8.2 github.com/pkg/errors v0.9.1 github.com/spf13/cobra v1.6.0 github.com/stretchr/testify v1.8.1 @@ -29,6 +28,7 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect + github.com/docker/go-units v0.5.0 // indirect github.com/emicklei/go-restful/v3 v3.10.2 // indirect github.com/evanphx/json-patch v5.6.0+incompatible // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect diff --git a/go.sum b/go.sum index aaf6eabae..693ced042 100644 --- a/go.sum +++ b/go.sum @@ -68,8 +68,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw= -github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= +github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= @@ -220,8 +220,6 @@ github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7P github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= -github.com/jpillora/go-ogle-analytics v0.0.0-20161213085824-14b04e0594ef h1:jLpa0vamfyIGeIJ/CfUJEWoKriw4ODeOgF1XxDvgMZ4= -github.com/jpillora/go-ogle-analytics v0.0.0-20161213085824-14b04e0594ef/go.mod h1:PlwhC7q1VSK73InDzdDatVetQrTsQHIbOvcJAZzitY0= github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -310,8 +308,10 @@ github.com/onsi/gomega v1.27.3/go.mod h1:5vG284IBtfDAmDyrK+eGyZmUgUlmi+Wngqo557c github.com/onsi/gomega v1.27.4/go.mod h1:riYq/GJKh8hhoM01HN6Vmuy93AarCXCBGpvFDK3q3fQ= github.com/onsi/gomega v1.27.7 h1:fVih9JD6ogIiHUN6ePK7HJidyEDpWGVB5mzM7cWNXoU= github.com/onsi/gomega v1.27.7/go.mod h1:1p8OOlwo2iUUDsHnOrjE5UKYJ+e3W8eQ3qSlRahPmr4= -github.com/openebs/lib-csi v0.8.0 h1:lxhv/SRjS7DBz7vTLkaDPd/FJnUftofxSFTU4fdZzW0= -github.com/openebs/lib-csi v0.8.0/go.mod h1:4yc0Q1thH+oU80z73zGELfrOw2yeLdLNIRmcrxBxsBc= +github.com/openebs/google-analytics-4 v0.1.0 h1:6aUDbQoh1ezb+NU/MkapFKffogW4QK3WYt8g2UmENe8= +github.com/openebs/google-analytics-4 v0.1.0/go.mod h1:3DkQfGCo79pZhL76Xtg0/R7LNLMttW6Bm/uP0yiZQHU= +github.com/openebs/lib-csi v0.8.2 h1:HmoiZX3VXFPglwqnRPnRus7K58ixDWBa19OpPZGk2Ws= +github.com/openebs/lib-csi v0.8.2/go.mod h1:4yc0Q1thH+oU80z73zGELfrOw2yeLdLNIRmcrxBxsBc= github.com/pborman/uuid v0.0.0-20170612153648-e790cca94e6c/go.mod h1:VyrYX9gd7irzKovcSS6BIIEwPRkP2Wm2m9ufcdFSJ34= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= diff --git a/pkg/driver/controller.go b/pkg/driver/controller.go index c873416dd..154655641 100644 --- a/pkg/driver/controller.go +++ b/pkg/driver/controller.go @@ -26,6 +26,7 @@ import ( zfsapi "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/zfs/v1" clientset "github.com/openebs/zfs-localpv/pkg/generated/clientset/internalclientset" informers "github.com/openebs/zfs-localpv/pkg/generated/informer/externalversions" + "github.com/openebs/zfs-localpv/pkg/version" kubeinformers "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes" "sigs.k8s.io/controller-runtime/pkg/manager/signals" @@ -40,13 +41,13 @@ import ( "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" + analytics "github.com/openebs/google-analytics-4/usage" errors "github.com/openebs/lib-csi/pkg/common/errors" "github.com/openebs/lib-csi/pkg/common/helpers" schd "github.com/openebs/lib-csi/pkg/scheduler" "github.com/openebs/zfs-localpv/pkg/builder/snapbuilder" "github.com/openebs/zfs-localpv/pkg/builder/volbuilder" csipayload "github.com/openebs/zfs-localpv/pkg/response" - analytics "github.com/openebs/zfs-localpv/pkg/usage" zfs "github.com/openebs/zfs-localpv/pkg/zfs" ) @@ -56,6 +57,16 @@ const ( GB = 1000 * 1000 * 1000 Mi = 1024 * 1024 Gi = 1024 * 1024 * 1024 + + // Ping event is sent periodically + Ping string = "zfs-ping" + + // DefaultCASType Event application name constant for volume event + DefaultCASType string = "zfs-localpv" + + // LocalPVReplicaCount is the constant used by usage to represent + // replication factor in LocalPV + LocalPVReplicaCount string = "1" ) // controller is the server implementation @@ -120,8 +131,9 @@ func (cs *controller) init() error { go cs.zfsNodeInformer.Run(stopCh) if zfs.GoogleAnalyticsEnabled == "true" { - analytics.New().Build().InstallBuilder(true).Send() - go analytics.PingCheck() + analytics.RegisterVersionGetter(version.GetVersionDetails) + analytics.New().CommonBuild(DefaultCASType).InstallBuilder(true).Send() + go analytics.PingCheck(DefaultCASType, Ping) } // wait for all the caches to be populated. @@ -142,14 +154,13 @@ var SupportedVolumeCapabilityAccessModes = []*csi.VolumeCapability_AccessMode{ } // sendEventOrIgnore sends anonymous local-pv provision/delete events -func sendEventOrIgnore(pvcName, pvName, capacity, stgType, method string) { +func sendEventOrIgnore(pvcName, pvName, capacity, method string) { if zfs.GoogleAnalyticsEnabled == "true" { - analytics.New().Build().ApplicationBuilder(). - SetVolumeType(stgType, method). - SetDocumentTitle(pvName). - SetCampaignName(pvcName). + analytics.New().CommonBuild(DefaultCASType).ApplicationBuilder(). + SetVolumeName(pvName). + SetVolumeClaimName(pvcName). SetLabel(analytics.EventLabelCapacity). - SetReplicaCount(analytics.LocalPVReplicaCount, method). + SetReplicaCount(LocalPVReplicaCount, method). SetCategory(method). SetVolumeCapacity(capacity).Send() } @@ -470,7 +481,7 @@ func (cs *controller) CreateVolume( klog.Infof("created the volume %s/%s on node %s", pool, volName, selected) - sendEventOrIgnore(pvcName, volName, strconv.FormatInt(int64(size), 10), "zfs-localpv", analytics.VolumeProvision) + sendEventOrIgnore(pvcName, volName, strconv.FormatInt(int64(size), 10), analytics.VolumeProvision) nodeid, err := zfs.GetNodeID(selected) if err != nil { @@ -534,7 +545,7 @@ func (cs *controller) DeleteVolume( ) } - sendEventOrIgnore("", volumeID, vol.Spec.Capacity, "zfs-localpv", analytics.VolumeDeprovision) + sendEventOrIgnore("", volumeID, vol.Spec.Capacity, analytics.VolumeDeprovision) deleteResponse: return csipayload.NewDeleteVolumeResponseBuilder().Build(), nil diff --git a/pkg/usage/const.go b/pkg/usage/const.go deleted file mode 100644 index b99b369ed..000000000 --- a/pkg/usage/const.go +++ /dev/null @@ -1,54 +0,0 @@ -/* -Copyright 2020 The OpenEBS Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package usage - -const ( - // GAclientID is the unique code of OpenEBS project in Google Analytics - GAclientID string = "UA-127388617-1" - - // supported events categories - - // InstallEvent event is sent on pod starts - InstallEvent string = "install" - // Ping event is sent periodically - Ping string = "zfs-ping" - // VolumeProvision event is sent when a volume is created - VolumeProvision string = "volume-provision" - // VolumeDeprovision event is sent when a volume is deleted - VolumeDeprovision string = "volume-deprovision" - // AppName the application name - AppName string = "OpenEBS" - - // RunningStatus status is running - RunningStatus string = "running" - // EventLabelNode holds the string label "nodes" - EventLabelNode string = "nodes" - // EventLabelCapacity holds the string label "capacity" - EventLabelCapacity string = "capacity" - - // Replica Event replication - Replica string = "replica:" - // DefaultReplicaCount holds the replica count string - DefaultReplicaCount string = "replica:1" - - // DefaultCASType Event application name constant for volume event - DefaultCASType string = "zfs-localpv" - - // LocalPVReplicaCount is the constant used by usage to represent - // replication factor in LocalPV - LocalPVReplicaCount string = "1" -) diff --git a/pkg/usage/googleanalytics.go b/pkg/usage/googleanalytics.go deleted file mode 100644 index ad058dbbb..000000000 --- a/pkg/usage/googleanalytics.go +++ /dev/null @@ -1,54 +0,0 @@ -/* -Copyright 2020 The OpenEBS Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package usage - -import ( - analytics "github.com/jpillora/go-ogle-analytics" - "k8s.io/klog/v2" -) - -// Send sends a single usage metric to Google Analytics with some -// compulsory fields defined in Google Analytics API -// bindings(jpillora/go-ogle-analytics) -func (u *Usage) Send() { - // Instantiate a Gclient with the tracking ID - go func() { - // Un-wrap the gaClient struct back here - gaClient, err := analytics.NewClient(u.Gclient.trackID) - if err != nil { - return - } - gaClient.ClientID(u.clientID). - CampaignSource(u.campaignSource). - CampaignContent(u.clientID). - CampaignName(u.campaignName). - ApplicationID(u.appID). - ApplicationVersion(u.appVersion). - DataSource(u.dataSource). - ApplicationName(u.appName). - ApplicationInstallerID(u.appInstallerID). - DocumentTitle(u.documentTitle) - // Un-wrap the Event struct back here - event := analytics.NewEvent(u.category, u.action) - event.Label(u.label) - event.Value(u.value) - if err := gaClient.Send(event); err != nil { - klog.Errorf(err.Error()) - return - } - }() -} diff --git a/pkg/usage/ping.go b/pkg/usage/ping.go deleted file mode 100644 index ed73f99fa..000000000 --- a/pkg/usage/ping.go +++ /dev/null @@ -1,66 +0,0 @@ -/* -Copyright 2020 The OpenEBS Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package usage - -import ( - "fmt" - "time" - - "github.com/openebs/lib-csi/pkg/common/env" -) - -// OpenEBSPingPeriod ping interval of volume io analytics -var OpenEBSPingPeriod = "OPENEBS_IO_ANALYTICS_PING_INTERVAL" - -const ( - // defaultPingPeriod sets the default ping heartbeat interval - defaultPingPeriod time.Duration = 24 * time.Hour - // minimumPingPeriod sets the minimum possible configurable - // heartbeat period, if a value lower than this will be set, the - // defaultPingPeriod will be used - minimumPingPeriod time.Duration = 1 * time.Hour -) - -// PingCheck sends ping events to Google Analytics -func PingCheck() { - // Create a new usage field - u := New() - duration := getPingPeriod() - ticker := time.NewTicker(duration) - for range ticker.C { - u.Build(). - InstallBuilder(true). - SetCategory(Ping). - Send() - } -} - -// getPingPeriod sets the duration of health events, defaults to 24 -func getPingPeriod() time.Duration { - value := env.GetOrDefault(OpenEBSPingPeriod, fmt.Sprint(defaultPingPeriod)) - duration, _ := time.ParseDuration(value) - // Sanitychecks for setting time duration of health events - // This way, we are checking for negative and zero time duration and we - // also have a minimum possible configurable time duration between health events - if duration < minimumPingPeriod { - // Avoid corner case when the ENV value is undesirable - return time.Duration(defaultPingPeriod) - } - - return time.Duration(duration) - -} diff --git a/pkg/usage/ping_test.go b/pkg/usage/ping_test.go deleted file mode 100644 index 1d1f3bc5f..000000000 --- a/pkg/usage/ping_test.go +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2020 The OpenEBS Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package usage - -import ( - "os" - "testing" - "time" -) - -func TestGetPingPeriod(t *testing.T) { - beforeFunc := func(value string) { - if err := os.Setenv(string(OpenEBSPingPeriod), value); err != nil { - t.Logf("Unable to set environment variable") - } - } - afterFunc := func() { - if err := os.Unsetenv(string(OpenEBSPingPeriod)); err != nil { - t.Logf("Unable to unset environment variable") - } - } - testSuite := map[string]struct { - OpenEBSPingPeriodValue string - ExpectedPeriodValue time.Duration - }{ - "24 seconds": {"24s", 86400000000000}, - "24 minutes": {"24m", 86400000000000}, - "24 hours": {"24h", 86400000000000}, - "Negative 24 hours": {"-24h", 86400000000000}, - "Random string input": {"Apache", 86400000000000}, - "Two hours": {"2h", 7200000000000}, - "Three hundred hours": {"300h", 1080000000000000}, - "Fifty two seconds": {"52000000000ns", 86400000000000}, - "Empty env value": {"", 86400000000000}, - } - for testKey, testData := range testSuite { - beforeFunc(testData.OpenEBSPingPeriodValue) - evaluatedValue := getPingPeriod() - if evaluatedValue != testData.ExpectedPeriodValue { - t.Fatalf("Tests failed for %s, expected=%d, got=%d", testKey, testData.ExpectedPeriodValue, evaluatedValue) - } - afterFunc() - } -} diff --git a/pkg/usage/size.go b/pkg/usage/size.go deleted file mode 100644 index c435d0d4f..000000000 --- a/pkg/usage/size.go +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright 2020 The OpenEBS Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package usage - -import units "github.com/docker/go-units" - -// toGigaUnits converts a size from xB to bytes where x={k,m,g,t,p...} -// and return the number of Gigabytes as an integer -// 1 gigabyte=1000 megabyte -func toGigaUnits(size string) (int64, error) { - sizeInBytes, err := units.FromHumanSize(size) - return sizeInBytes / units.GB, err -} diff --git a/pkg/usage/size_test.go b/pkg/usage/size_test.go deleted file mode 100644 index 23e85634a..000000000 --- a/pkg/usage/size_test.go +++ /dev/null @@ -1,61 +0,0 @@ -/* -Copyright 2020 The OpenEBS Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package usage - -import "testing" - -func TestToGigaUnits(t *testing.T) { - tests := map[string]struct { - stringSize string - expectedGsize int64 - positiveTest bool - }{ - "One Hundred Twenty Three thousand Four Hundred Fifty Six Teribytes": { - "123456 TiB", - 123456000, - true, - }, - "One Gibibyte": { - "1 GiB", - 1, - true, - }, - "One Megabyte": { - "1 MB", - 0, // One cannot express <1GB in integer - true, - }, - "One Megabyte negative-case": { - "1 MB", - 1, - false, - // 1 MB isn't 1 GB - }, - "One hundred four point five gigabyte": { - "104.5 GB", - 104, - true, - }, - } - - for testKey, testSuite := range tests { - gotValue, err := toGigaUnits(testSuite.stringSize) - if (gotValue != testSuite.expectedGsize || err != nil) && testSuite.positiveTest { - t.Fatalf("Tests failed for %s, expected=%d, got=%d", testKey, testSuite.expectedGsize, gotValue) - } - } -} diff --git a/pkg/usage/usage.go b/pkg/usage/usage.go deleted file mode 100644 index e36bf1c7b..000000000 --- a/pkg/usage/usage.go +++ /dev/null @@ -1,267 +0,0 @@ -/* -Copyright 2020 The OpenEBS Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package usage - -import ( - k8sapi "github.com/openebs/lib-csi/pkg/client/k8s" -) - -// Usage struct represents all information about a usage metric sent to -// Google Analytics with respect to the application -type Usage struct { - // Embedded Event struct as we are currently only sending hits of type - // 'event' - Event - - // https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#an - // use-case: cstor or jiva volume, or m-apiserver application - // Embedded field for application - Application - - // Embedded Gclient struct - Gclient -} - -// Event is a represents usage of OpenEBS -// Event contains all the query param fields when hits is of type='event' -// Ref: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ec -type Event struct { - // (Required) Event Category, ec - category string - // (Required) Event Action, ea - action string - // (Optional) Event Label, el - label string - // (Optional) Event vallue, ev - // Non negative - value int64 -} - -// NewEvent returns an Event struct with eventCategory, eventAction, -// eventLabel, eventValue fields -func (u *Usage) NewEvent(c, a, l string, v int64) *Usage { - u.category = c - u.action = a - u.label = l - u.value = v - return u -} - -// Application struct holds details about the Application -type Application struct { - // eg. project version - appVersion string - - // eg. kubernetes version - appInstallerID string - - // Name of the application, usage(OpenEBS/NDM) - appID string - - // eg. usage(os-type/architecture) of system or volume's CASType - appName string -} - -// Gclient struct represents a Google Analytics hit -type Gclient struct { - // constant tracking-id used to send a hit - trackID string - - // anonymous client-id - clientID string - - // anonymous campaign source - campaignSource string - - // anonymous campaign name - campaignName string - - // https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ds - // (usecase) node-detail - dataSource string - - // Document-title property in Google Analytics - // https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#dt - // use-case: uuid of the volume objects or a uuid to anonymously tell objects apart - documentTitle string -} - -// New returns an instance of Usage -func New() *Usage { - return &Usage{} -} - -// SetDataSource : usage(os-type, kernel) -func (u *Usage) SetDataSource(dataSource string) *Usage { - u.dataSource = dataSource - return u -} - -// SetTrackingID Sets the GA-code for the project -func (u *Usage) SetTrackingID(track string) *Usage { - u.trackID = track - return u -} - -// SetCampaignSource : source of openebs installater like: -// helm or operator etc. This will have to be configured -// via ENV variable OPENEBS_IO_INSTALLER_TYPE -func (u *Usage) SetCampaignSource(campaignSrc string) *Usage { - u.campaignSource = campaignSrc - return u -} - -// SetDocumentTitle : usecase(anonymous-id) -func (u *Usage) SetDocumentTitle(documentTitle string) *Usage { - u.documentTitle = documentTitle - return u -} - -// SetApplicationName : usecase(os-type/arch, volume CASType) -func (u *Usage) SetApplicationName(appName string) *Usage { - u.appName = appName - return u -} - -// SetCampaignName : set the name of the PVC or will be empty. -func (u *Usage) SetCampaignName(campaignName string) *Usage { - u.campaignName = campaignName - return u -} - -// SetApplicationID : usecase(OpenEBS/NDM) -func (u *Usage) SetApplicationID(appID string) *Usage { - u.appID = appID - return u -} - -// SetApplicationVersion : usecase(project-version) -func (u *Usage) SetApplicationVersion(appVersion string) *Usage { - u.appVersion = appVersion - return u -} - -// SetApplicationInstallerID : usecase(k8s-version) -func (u *Usage) SetApplicationInstallerID(appInstallerID string) *Usage { - u.appInstallerID = appInstallerID - return u -} - -// SetClientID sets the anonymous user id -func (u *Usage) SetClientID(userID string) *Usage { - u.clientID = userID - return u -} - -// SetCategory sets the category of an event -func (u *Usage) SetCategory(c string) *Usage { - u.category = c - return u -} - -// SetAction sets the action of an event -func (u *Usage) SetAction(a string) *Usage { - u.action = a - return u -} - -// SetLabel sets the label for an event -func (u *Usage) SetLabel(l string) *Usage { - u.label = l - return u -} - -// SetValue sets the value for an event's label -func (u *Usage) SetValue(v int64) *Usage { - u.value = v - return u -} - -// Build is a builder method for Usage struct -func (u *Usage) Build() *Usage { - // Default ApplicationID for openebs project is OpenEBS - v := NewVersion() - v.getVersion(false) - u.SetApplicationID(AppName). - SetTrackingID(GAclientID). - SetClientID(v.id). - SetCampaignSource(v.installerType) - // TODO: Add condition for version over-ride - // Case: CAS/Jiva version, etc - return u -} - -// ApplicationBuilder Application builder is used for adding k8s&openebs environment detail -// for non install events -func (u *Usage) ApplicationBuilder() *Usage { - v := NewVersion() - v.getVersion(false) - u.SetApplicationVersion(v.openebsVersion). - SetApplicationName(v.k8sArch). - SetApplicationInstallerID(v.k8sVersion). - SetDataSource(v.nodeType) - return u -} - -// SetVolumeCapacity sets the storage capacity of the volume for a volume event -func (u *Usage) SetVolumeCapacity(volCapG string) *Usage { - s, _ := toGigaUnits(volCapG) - u.SetValue(s) - return u -} - -// SetVolumeType Wrapper for setting the default storage-engine for volume-provision event -func (u *Usage) SetVolumeType(volType, method string) *Usage { - if method == VolumeProvision && volType == "" { - // Set the default storage engine, if not specified in the request - u.SetApplicationName(DefaultCASType) - } else { - u.SetApplicationName(volType) - } - return u -} - -// SetReplicaCount Wrapper for setting replica count for volume events -// NOTE: This doesn't get the replica count in a volume de-provision event. -// TODO: Pick the current value of replica-count from the CAS-engine -func (u *Usage) SetReplicaCount(count, method string) *Usage { - if method == VolumeProvision && count == "" { - // Case: When volume-provision the replica count isn't specified - // it is set to three by default by the m-apiserver - u.SetAction(DefaultReplicaCount) - } else { - // Catch all case for volume-deprovision event and - // volume-provision event with an overridden replica-count - u.SetAction(Replica + count) - } - return u -} - -// InstallBuilder is a concrete builder for install events -func (u *Usage) InstallBuilder(override bool) *Usage { - v := NewVersion() - clusterSize, _ := k8sapi.NumberOfNodes() - v.getVersion(override) - u.SetApplicationVersion(v.openebsVersion). - SetApplicationName(v.k8sArch). - SetApplicationInstallerID(v.k8sVersion). - SetDataSource(v.nodeType). - SetDocumentTitle(v.id). - SetApplicationID(AppName). - NewEvent(InstallEvent, RunningStatus, EventLabelNode, int64(clusterSize)) - return u -} diff --git a/pkg/usage/versionset.go b/pkg/usage/versionset.go deleted file mode 100644 index 5f5fef176..000000000 --- a/pkg/usage/versionset.go +++ /dev/null @@ -1,130 +0,0 @@ -/* -Copyright 2020 The OpenEBS Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package usage - -import ( - k8sapi "github.com/openebs/lib-csi/pkg/client/k8s" - env "github.com/openebs/lib-csi/pkg/common/env" - openebsversion "github.com/openebs/zfs-localpv/pkg/version" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/klog/v2" -) - -var ( - clusterUUID = "OPENEBS_IO_USAGE_UUID" - clusterVersion = "OPENEBS_IO_K8S_VERSION" - clusterArch = "OPENEBS_IO_K8S_ARCH" - openEBSversion = "OPENEBS_IO_VERSION_TAG" - nodeType = "OPENEBS_IO_NODE_TYPE" - installerType = "OPENEBS_IO_INSTALLER_TYPE" -) - -// VersionSet is a struct which stores (sort of) fixed information about a -// k8s environment -type VersionSet struct { - id string // OPENEBS_IO_USAGE_UUID - k8sVersion string // OPENEBS_IO_K8S_VERSION - k8sArch string // OPENEBS_IO_K8S_ARCH - openebsVersion string // OPENEBS_IO_VERSION_TAG - nodeType string // OPENEBS_IO_NODE_TYPE - installerType string // OPENEBS_IO_INSTALLER_TYPE -} - -// NewVersion returns a new versionSet struct -func NewVersion() *VersionSet { - return &VersionSet{} -} - -// fetchAndSetVersion consumes the Kubernetes API to get environment constants -// and returns a versionSet struct -func (v *VersionSet) fetchAndSetVersion() error { - var err error - v.id, err = getUUIDbyNS("default") - if err != nil { - return err - } - - err = env.Set(clusterUUID, v.id) - if err != nil { - return err - } - - k8s, err := k8sapi.GetServerVersion() - if err != nil { - return err - } - // eg. linux/amd64 - v.k8sArch = k8s.Platform - v.k8sVersion = k8s.GitVersion - - err = env.Set(clusterArch, v.k8sArch) - if err != nil { - return err - } - - err = env.Set(clusterVersion, v.k8sVersion) - if err != nil { - return err - } - - v.nodeType, err = k8sapi.GetOSAndKernelVersion() - if err != nil { - return err - } - - env.Set(nodeType, v.nodeType) - if err != nil { - return err - } - v.openebsVersion = openebsversion.GetVersionDetails() - - err = env.Set(openEBSversion, v.openebsVersion) - return err -} - -// getVersion is a wrapper over fetchAndSetVersion -func (v *VersionSet) getVersion(override bool) error { - // If ENVs aren't set or the override is true, fetch the required - // values from the K8s APIserver - if _, present := env.Lookup(openEBSversion); !present || override { - if err := v.fetchAndSetVersion(); err != nil { - klog.Error(err.Error()) - return err - } - } - // Fetch data from ENV - v.id = env.Get(clusterUUID) - v.k8sArch = env.Get(clusterArch) - v.k8sVersion = env.Get(clusterVersion) - v.nodeType = env.Get(nodeType) - v.openebsVersion = env.Get(openEBSversion) - v.installerType = env.Get(installerType) - return nil -} - -// getUUIDbyNS returns the metadata.object.uid of a namespace in Kubernetes -func getUUIDbyNS(namespace string) (string, error) { - ns := k8sapi.Namespace() - NSstruct, err := ns.Get(namespace, metav1.GetOptions{}) - if err != nil { - return "", err - } - if NSstruct != nil { - return string(NSstruct.GetObjectMeta().GetUID()), nil - } - return "", nil -} From 932f002c6fd887a66e380eb3154a4568a7195fc7 Mon Sep 17 00:00:00 2001 From: Hrudaya Ranjan Sahoo Date: Wed, 29 Nov 2023 09:32:05 +0530 Subject: [PATCH 4/7] feat(usedcapcity): kubectl describe zfsnode should show the used capacity information (#485) Signed-off-by: Hrudaya --- deploy/yamls/zfsnode-crd.yaml | 8 ++++++++ deploy/zfs-operator.yaml | 8 ++++++++ pkg/apis/openebs.io/zfs/v1/zfsnode.go | 4 ++++ pkg/zfs/zfs_util.go | 9 ++++++++- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/deploy/yamls/zfsnode-crd.yaml b/deploy/yamls/zfsnode-crd.yaml index db0540d4b..065827955 100644 --- a/deploy/yamls/zfsnode-crd.yaml +++ b/deploy/yamls/zfsnode-crd.yaml @@ -60,6 +60,13 @@ spec: description: Free specifies the available capacity of zfs pool. pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ x-kubernetes-int-or-string: true + used: + anyOf: + - type: integer + - type: string + description: Used specifies the used capacity of zfs pool. + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true name: description: Name of the zfs pool. minLength: 1 @@ -70,6 +77,7 @@ spec: type: string required: - free + - used - name - uuid type: object diff --git a/deploy/zfs-operator.yaml b/deploy/zfs-operator.yaml index 82db833c8..983eb9c99 100644 --- a/deploy/zfs-operator.yaml +++ b/deploy/zfs-operator.yaml @@ -1267,6 +1267,13 @@ spec: description: Free specifies the available capacity of zfs pool. pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ x-kubernetes-int-or-string: true + used: + anyOf: + - type: integer + - type: string + description: Used specifies the used capacity of zfs pool. + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true name: description: Name of the zfs pool. minLength: 1 @@ -1277,6 +1284,7 @@ spec: type: string required: - free + - used - name - uuid type: object diff --git a/pkg/apis/openebs.io/zfs/v1/zfsnode.go b/pkg/apis/openebs.io/zfs/v1/zfsnode.go index 75a5ed85a..db5830c46 100644 --- a/pkg/apis/openebs.io/zfs/v1/zfsnode.go +++ b/pkg/apis/openebs.io/zfs/v1/zfsnode.go @@ -53,6 +53,10 @@ type Pool struct { // Free specifies the available capacity of zfs pool. // +kubebuilder:validation:Required Free resource.Quantity `json:"free"` + + // Used specifies the used capacity of zfs pool. + // +kubebuilder:validation:Required + Used resource.Quantity `json:"used"` } // ZFSNodeList is a collection of ZFSNode resources diff --git a/pkg/zfs/zfs_util.go b/pkg/zfs/zfs_util.go index 4ae9a6398..2c9b331e2 100644 --- a/pkg/zfs/zfs_util.go +++ b/pkg/zfs/zfs_util.go @@ -922,7 +922,7 @@ func CreateRestore(rstr *apis.ZFSRestore) error { func ListZFSPool() ([]apis.Pool, error) { args := []string{ ZFSListArg, "-d", "1", "-s", "name", - "-o", "name,guid,available", + "-o", "name,guid,available,used", "-H", "-p", } cmd := exec.Command(ZFSVolCmd, args...) @@ -956,6 +956,13 @@ func decodeListOutput(raw []byte) ([]apis.Pool, error) { return pools, err } pool.Free = *resource.NewQuantity(sizeBytes, resource.BinarySI) + usedBytes, err := strconv.ParseInt(items[3], + 10, 64) + if err != nil { + err = fmt.Errorf("cannot get free size for pool %v: %v", pool.Name, err) + return pools, err + } + pool.Used = *resource.NewQuantity(usedBytes, resource.BinarySI) pools = append(pools, pool) } } From d646e6b1aa779e986b8cbf5ce65b400f243c557b Mon Sep 17 00:00:00 2001 From: Niladri Halder Date: Mon, 11 Dec 2023 23:14:37 +0530 Subject: [PATCH 5/7] chore(changelog): update changelog for v2.4.0 (#495) Signed-off-by: Niladri Halder --- CHANGELOG.md | 10 +++++++++- changelogs/released/v2.3.0/455-jnels124 | 1 + changelogs/released/v2.3.0/487-trunet | 1 + changelogs/released/v2.4.0/480-hrudaya21 | 1 + changelogs/released/v2.4.0/485-hrudaya21 | 1 + changelogs/released/v2.4.0/490-Abhinandan-Purkait | 1 + changelogs/unreleased/454-jnels124.md | 1 - changelogs/unreleased/487-trunet.md | 1 - 8 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 changelogs/released/v2.3.0/455-jnels124 create mode 100644 changelogs/released/v2.3.0/487-trunet create mode 100644 changelogs/released/v2.4.0/480-hrudaya21 create mode 100644 changelogs/released/v2.4.0/485-hrudaya21 create mode 100644 changelogs/released/v2.4.0/490-Abhinandan-Purkait delete mode 100644 changelogs/unreleased/454-jnels124.md delete mode 100644 changelogs/unreleased/487-trunet.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 83a56056a..b67cbb516 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ +v2.4.0 / 2023-12-12 +======================== +* fix(localpv): restore size to return as part of snapshot create response ([#480](https://github.com/openebs/zfs-localpv/pull/480),[@hrudaya21](https://github.com/hrudaya21)) +* feat(usedcapcity): kubectl describe zfsnode should show the used capacity information ([#485](https://github.com/openebs/zfs-localpv/pull/485),[@hrudaya21](https://github.com/hrudaya21)) +* feat(event): update ua to ga4 analytics ([#490](https://github.com/openebs/zfs-localpv/pull/490),[@Abhinandan-Purkait](https://github.com/Abhinandan-Purkait)) + v2.3.0 / 2023-07-23 ======================== * feat(csi): bump up csi provisioner to v3.5.0 and other updates ([#457](https://github.com/openebs/zfs-localpv/pull/457),[@vharsh](https://github.com/vharsh)) +* feat(helm): add support for providing additional volumes and adding init containers ([#455](https://github.com/openebs/zfs-localpv/pull/455),[@jnels124](https://github.com/jnels124)) +* fix(helm): Possibility to override zfs encryption keys directory ([#487](https://github.com/openebs/zfs-localpv/pull/487),[@trunet](https://github.com/trunet)) v2.2.0 / 2023-05-29 ======================== @@ -9,7 +17,7 @@ v2.2.0 / 2023-05-29 v2.0.0 / 2022-01-11 ======================== -* fix (localpv): fixing CSIStorageCapacity when "poolname" param has child dataset ([#393](https://github.com/openebs/zfs-localpv/pull/393),[@netom](https://github.com/netom)) +* fix(localpv): fixing CSIStorageCapacity when "poolname" param has child dataset ([#393](https://github.com/openebs/zfs-localpv/pull/393),[@netom](https://github.com/netom)) v1.7.0 / 2021-03-15 ======================== diff --git a/changelogs/released/v2.3.0/455-jnels124 b/changelogs/released/v2.3.0/455-jnels124 new file mode 100644 index 000000000..3714dce03 --- /dev/null +++ b/changelogs/released/v2.3.0/455-jnels124 @@ -0,0 +1 @@ +add support for specify additional volumes and init containers to the CSI controller and node drivers \ No newline at end of file diff --git a/changelogs/released/v2.3.0/487-trunet b/changelogs/released/v2.3.0/487-trunet new file mode 100644 index 000000000..249ec2760 --- /dev/null +++ b/changelogs/released/v2.3.0/487-trunet @@ -0,0 +1 @@ +add helm values option to override directory path for encryption keys \ No newline at end of file diff --git a/changelogs/released/v2.4.0/480-hrudaya21 b/changelogs/released/v2.4.0/480-hrudaya21 new file mode 100644 index 000000000..8c28e1e2c --- /dev/null +++ b/changelogs/released/v2.4.0/480-hrudaya21 @@ -0,0 +1 @@ +add restore size to return as part of CSI snapshot create response \ No newline at end of file diff --git a/changelogs/released/v2.4.0/485-hrudaya21 b/changelogs/released/v2.4.0/485-hrudaya21 new file mode 100644 index 000000000..dcff9a94b --- /dev/null +++ b/changelogs/released/v2.4.0/485-hrudaya21 @@ -0,0 +1 @@ +add the used capacity to ZFS Node resource spec \ No newline at end of file diff --git a/changelogs/released/v2.4.0/490-Abhinandan-Purkait b/changelogs/released/v2.4.0/490-Abhinandan-Purkait new file mode 100644 index 000000000..bfca01901 --- /dev/null +++ b/changelogs/released/v2.4.0/490-Abhinandan-Purkait @@ -0,0 +1 @@ +update google analytics client from UA to GA4 \ No newline at end of file diff --git a/changelogs/unreleased/454-jnels124.md b/changelogs/unreleased/454-jnels124.md deleted file mode 100644 index 6581bfcf5..000000000 --- a/changelogs/unreleased/454-jnels124.md +++ /dev/null @@ -1 +0,0 @@ -add support to deployment yaml to allower user to specify additional volumes and init containers \ No newline at end of file diff --git a/changelogs/unreleased/487-trunet.md b/changelogs/unreleased/487-trunet.md deleted file mode 100644 index 2da45404e..000000000 --- a/changelogs/unreleased/487-trunet.md +++ /dev/null @@ -1 +0,0 @@ -fix(helm): Possibility to override zfs encryption keys directory \ No newline at end of file From b6fed7fa8a3a00156619e79481d25b6815959ff1 Mon Sep 17 00:00:00 2001 From: Hrudaya Ranjan Sahoo Date: Thu, 14 Dec 2023 19:10:05 +0530 Subject: [PATCH 6/7] feat(deploy/helm): move volumesnapshot CRDs to the template dir (#488) Signed-off-by: Hrudaya --- deploy/helm/charts/Chart.yaml | 4 ++-- deploy/helm/charts/crds/zfsnode.yaml | 8 ++++++++ .../charts/{crds => templates}/volumesnapshotclasses.yaml | 4 +++- .../{crds => templates}/volumesnapshotcontents.yaml | 4 +++- .../helm/charts/{crds => templates}/volumesnapshots.yaml | 4 +++- deploy/helm/charts/values.yaml | 8 +++++--- 6 files changed, 24 insertions(+), 8 deletions(-) rename deploy/helm/charts/{crds => templates}/volumesnapshotclasses.yaml (98%) rename deploy/helm/charts/{crds => templates}/volumesnapshotcontents.yaml (99%) rename deploy/helm/charts/{crds => templates}/volumesnapshots.yaml (99%) diff --git a/deploy/helm/charts/Chart.yaml b/deploy/helm/charts/Chart.yaml index 20d0fdc14..bbadfff82 100644 --- a/deploy/helm/charts/Chart.yaml +++ b/deploy/helm/charts/Chart.yaml @@ -1,8 +1,8 @@ apiVersion: v2 name: zfs-localpv description: Helm chart for CSI Driver for dynamic provisioning of ZFS Persistent Local Volumes. For instructions on how to use this helm chart, see - https://openebs.github.io/zfs-localpv/ -version: 2.3.2 -appVersion: 2.3.0 +version: 2.4.0 +appVersion: 2.4.0 icon: https://raw.githubusercontent.com/cncf/artwork/master/projects/openebs/icon/color/openebs-icon-color.png home: https://openebs.io/ keywords: diff --git a/deploy/helm/charts/crds/zfsnode.yaml b/deploy/helm/charts/crds/zfsnode.yaml index db0540d4b..065827955 100644 --- a/deploy/helm/charts/crds/zfsnode.yaml +++ b/deploy/helm/charts/crds/zfsnode.yaml @@ -60,6 +60,13 @@ spec: description: Free specifies the available capacity of zfs pool. pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ x-kubernetes-int-or-string: true + used: + anyOf: + - type: integer + - type: string + description: Used specifies the used capacity of zfs pool. + pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ + x-kubernetes-int-or-string: true name: description: Name of the zfs pool. minLength: 1 @@ -70,6 +77,7 @@ spec: type: string required: - free + - used - name - uuid type: object diff --git a/deploy/helm/charts/crds/volumesnapshotclasses.yaml b/deploy/helm/charts/templates/volumesnapshotclasses.yaml similarity index 98% rename from deploy/helm/charts/crds/volumesnapshotclasses.yaml rename to deploy/helm/charts/templates/volumesnapshotclasses.yaml index 3500b8bb4..dd6d0c5f7 100644 --- a/deploy/helm/charts/crds/volumesnapshotclasses.yaml +++ b/deploy/helm/charts/templates/volumesnapshotclasses.yaml @@ -1,3 +1,4 @@ +{{- if .Values.crd.volumeSnapshot }} --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition @@ -131,4 +132,5 @@ status: kind: "" plural: "" conditions: [] - storedVersions: [] \ No newline at end of file + storedVersions: [] +{{- end }} \ No newline at end of file diff --git a/deploy/helm/charts/crds/volumesnapshotcontents.yaml b/deploy/helm/charts/templates/volumesnapshotcontents.yaml similarity index 99% rename from deploy/helm/charts/crds/volumesnapshotcontents.yaml rename to deploy/helm/charts/templates/volumesnapshotcontents.yaml index f69459064..b6d587fea 100644 --- a/deploy/helm/charts/crds/volumesnapshotcontents.yaml +++ b/deploy/helm/charts/templates/volumesnapshotcontents.yaml @@ -1,3 +1,4 @@ +{{- if .Values.crd.volumeSnapshot }} --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition @@ -398,4 +399,5 @@ status: kind: "" plural: "" conditions: [] - storedVersions: [] \ No newline at end of file + storedVersions: [] +{{- end }} \ No newline at end of file diff --git a/deploy/helm/charts/crds/volumesnapshots.yaml b/deploy/helm/charts/templates/volumesnapshots.yaml similarity index 99% rename from deploy/helm/charts/crds/volumesnapshots.yaml rename to deploy/helm/charts/templates/volumesnapshots.yaml index bf534c4bd..ac8ce780f 100644 --- a/deploy/helm/charts/crds/volumesnapshots.yaml +++ b/deploy/helm/charts/templates/volumesnapshots.yaml @@ -1,3 +1,4 @@ +{{- if .Values.crd.volumeSnapshot }} --- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition @@ -309,4 +310,5 @@ status: kind: "" plural: "" conditions: [] - storedVersions: [] \ No newline at end of file + storedVersions: [] +{{- end }} \ No newline at end of file diff --git a/deploy/helm/charts/values.yaml b/deploy/helm/charts/values.yaml index 8bf2f9156..e57bfcfba 100644 --- a/deploy/helm/charts/values.yaml +++ b/deploy/helm/charts/values.yaml @@ -2,7 +2,7 @@ # This is a YAML-formatted file. # Declare variables to be passed into your templates. release: - version: "2.3.1" + version: "2.4.0" imagePullSecrets: # - name: "image-pull-secret" @@ -144,13 +144,15 @@ zfsPlugin: repository: openebs/zfs-driver pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. - tag: 2.3.0 + tag: 2.4.0 role: openebs-zfs crd: enableInstall: true - + # Specify installation of the kubernetes-csi volume snapshot CRDs if your Kubernetes distribution + # or another storage operator already manages them. + volumeSnapshot: true serviceAccount: zfsController: # Specifies whether a service account should be created From 6b0942cbec61a89053cb679bb4e838d28a43b228 Mon Sep 17 00:00:00 2001 From: Jesse Nelson Date: Tue, 19 Dec 2023 22:54:43 -0600 Subject: [PATCH 7/7] fix(plugin): Fix ability to have custom value for openebs.io/nodeid (#451) * fix(plugin): fix node id to node mapping Signed-off-by: Jesse Nelson * add change log Signed-off-by: Jesse Nelson * fix case when nodeid not set Signed-off-by: Jesse Nelson * simplify logic Signed-off-by: Jesse Nelson * update doc Signed-off-by: Jesse Nelson * fix cases where nodeid not set Signed-off-by: Jesse Nelson * check for error first Signed-off-by: Jesse Nelson --------- Signed-off-by: Jesse Nelson --- README.md | 2 ++ changelogs/unreleased/450-nodeid-fix.md | 1 + pkg/driver/controller.go | 7 +++- pkg/mgmt/zfsnode/start.go | 43 ++++++++++++++++++++++--- 4 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 changelogs/unreleased/450-nodeid-fix.md diff --git a/README.md b/README.md index 4f11a4002..7c8a88d4c 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,8 @@ Configure the custom topology keys (if needed). This can be used for many purpos https://github.com/openebs/zfs-localpv/blob/HEAD/docs/faq.md#6-how-to-add-custom-topology-key ### Installation +In order to support moving data to a new node later on, you must label each node with a unique value for `openebs.io/nodeid`. +For more information on migrating data, please [see here](docs/faq.md#8-how-to-migrate-pvs-to-the-new-node-in-case-old-node-is-not-accessible) We can install the latest release of OpenEBS ZFS driver by running the following command: ```bash diff --git a/changelogs/unreleased/450-nodeid-fix.md b/changelogs/unreleased/450-nodeid-fix.md new file mode 100644 index 000000000..eeef98d0d --- /dev/null +++ b/changelogs/unreleased/450-nodeid-fix.md @@ -0,0 +1 @@ +fix regression introduced with v2.0.0 that caused the plugin code to not be able to start when a user sets openebs.io/nodeid \ No newline at end of file diff --git a/pkg/driver/controller.go b/pkg/driver/controller.go index 154655641..23acb2b1c 100644 --- a/pkg/driver/controller.go +++ b/pkg/driver/controller.go @@ -918,7 +918,12 @@ func (cs *controller) GetCapacity( var availableCapacity int64 for _, nodeName := range nodeNames { - v, exists, err := zfsNodesCache.GetByKey(zfs.OpenEBSNamespace + "/" + nodeName) + mappedNodeId, mapErr := zfs.GetNodeID(nodeName) + if mapErr != nil { + klog.Warningf("Unable to find mapped node id for %s", nodeName) + mappedNodeId = nodeName + } + v, exists, err := zfsNodesCache.GetByKey(zfs.OpenEBSNamespace + "/" + mappedNodeId) if err != nil { klog.Warning("unexpected error after querying the zfsNode informer cache") continue diff --git a/pkg/mgmt/zfsnode/start.go b/pkg/mgmt/zfsnode/start.go index 395ae4f92..20cf6bdad 100644 --- a/pkg/mgmt/zfsnode/start.go +++ b/pkg/mgmt/zfsnode/start.go @@ -18,6 +18,14 @@ package zfsnode import ( "context" + "fmt" + v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/fields" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/selection" + "k8s.io/klog/v2" + "os" + "strings" "sync" "time" @@ -27,7 +35,6 @@ import ( "github.com/openebs/zfs-localpv/pkg/zfs" "github.com/pkg/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/kubernetes" ) @@ -60,10 +67,38 @@ func Start(controllerMtx *sync.RWMutex, stopCh <-chan struct{}) error { options.FieldSelector = fields.OneTermEqualSelector("metadata.name", zfs.NodeID).String() })) - k8sNode, err := kubeClient.CoreV1().Nodes().Get(context.TODO(), zfs.NodeID, metav1.GetOptions{}) - if err != nil { - return errors.Wrapf(err, "fetch k8s node %s", zfs.NodeID) + nodeName := os.Getenv("OPENEBS_NODE_NAME") + var k8sNode v1.Node + + if len(strings.TrimSpace(zfs.NodeID)) == 0 || nodeName == zfs.NodeID { + k8sNodeCandidate, err := kubeClient.CoreV1().Nodes().Get(context.TODO(), zfs.NodeID, metav1.GetOptions{}) + + if err != nil { + return errors.Wrapf(err, "fetch k8s node %s", zfs.NodeID) + } + + k8sNode = *k8sNodeCandidate + + } else { + topologyRequirement, requirementError := labels.NewRequirement(zfs.ZFSTopologyKey, selection.Equals, []string{zfs.NodeID}) + if requirementError != nil { + return errors.Wrapf(requirementError, "Unable to generate topology requirement by %s for node id %s", zfs.ZFSTopologyKey, zfs.NodeID) + } + topologySelector := labels.NewSelector().Add(*topologyRequirement).String() + klog.Infof("The topology selector is %s", topologySelector) + + k8sNodeCandidate, err := kubeClient.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{ + LabelSelector: topologySelector, + }) + if err != nil { + return errors.Wrapf(err, "error trying to find node with label %s having value %s", zfs.ZFSTopologyKey, zfs.NodeID) + } + if k8sNodeCandidate == nil || len(k8sNodeCandidate.Items) != 1 { + return fmt.Errorf("unable to retrieve a single node by %s for %s", zfs.ZFSTopologyKey, zfs.NodeID) + } + k8sNode = k8sNodeCandidate.Items[0] } + isTrue := true // as object returned by client go clears all TypeMeta from it. nodeGVK := &schema.GroupVersionKind{