### Install go.yaml.in/yaml/v2 Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/go.yaml.in/yaml/v2/README.md Use 'go get' to install the v2 version of the YAML package for Go. ```bash go get go.yaml.in/yaml/v2 ``` -------------------------------- ### Install multierr Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/go.uber.org/multierr/README.md Use go get to install the latest version of the multierr library. ```bash go get -u go.uber.org/multierr@latest ``` -------------------------------- ### Install Zap Logging Library Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/go.uber.org/zap/README.md Use 'go get' to install the zap library. Zap supports the two most recent minor versions of Go. ```go go get -u go.uber.org/zap ``` -------------------------------- ### Install Cobra Library Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/spf13/cobra/README.md Use 'go get' to install the latest version of the Cobra library. ```bash go get -u github.com/spf13/cobra@latest ``` -------------------------------- ### Install etcd/clientv3 Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/go.etcd.io/etcd/client/v3/README.md Install the etcd/clientv3 package using go get. For pre-release versions, specify the version tag. ```bash go get go.etcd.io/etcd/client/v3 ``` ```bash go get go.etcd.io/etcd/client/v3@v3.5.0-pre ``` -------------------------------- ### Create, Snapshot, Clone, and Destroy ZFS Filesystem Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/mistifyio/go-zfs/README.md This example demonstrates the basic lifecycle of a ZFS filesystem using the go-zfs library. It assumes a ZFS pool named 'test' exists and omits error handling for brevity. Ensure you have the necessary ZFS setup and permissions. ```go //assuming a zpool named test //error handling omitted f, err := zfs.CreateFilesystem("test/snapshot-test", nil) ok(t, err) s, err := f.Snapshot("test", nil) ok(t, err) // snapshot is named "test/snapshot-test@test" c, err := s.Clone("test/clone-test", nil) err := c.Destroy() err := s.Destroy() err := f.Destroy() ``` -------------------------------- ### Install json-iterator/go Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/json-iterator/go/README.md Use the go get command to install the json-iterator/go library. ```bash go get github.com/json-iterator/go ``` -------------------------------- ### Install gziphandler Package Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/NYTimes/gziphandler/README.md Use 'go get' to install the latest version of the gziphandler package. ```bash go get -u github.com/NYTimes/gziphandler ``` -------------------------------- ### Install and Run Local Go Doc Site Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Installs and runs a local Go Doc site for viewing package documentation. Ensure you have the latest version installed. ```sh go install golang.org/x/pkgsite/cmd/pkgsite@latest pkgsite ``` -------------------------------- ### Install uuid Package Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/google/uuid/README.md Use 'go get' to install the uuid package. This command fetches and installs the package into your Go workspace. ```sh go get github.com/google/uuid ``` -------------------------------- ### Install Ginkgo Locally Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/onsi/ginkgo/v2/CONTRIBUTING.md Installs the Ginkgo CLI locally. Ensure you have Go installed and configured. ```bash go install ./... ``` -------------------------------- ### Install go.yaml.in/yaml/v3 Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/go.yaml.in/yaml/v3/README.md Run this command to install the package. The import path is go.yaml.in/yaml/v3. ```bash go get go.yaml.in/yaml/v3 ``` -------------------------------- ### Define a RESTful Web Service Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/emicklei/go-restful/v3/README.md Example demonstrating how to define a WebService with routes, request consumers, and response producers. Includes a GET route for retrieving a user by ID. ```go ws := new(restful.WebService) ws. Path("/users"). Consumes(restful.MIME_XML, restful.MIME_JSON). Produces(restful.MIME_JSON, restful.MIME_XML) ws.Route(ws.GET("/{user-id}").To(u.findUser). Doc("get a user"). Param(ws.PathParameter("user-id", "identifier of the user").DataType("string")), Writes(User{})) ... func (u UserResource) findUser(request *restful.Request, response *restful.Response) { id := request.PathParameter("user-id") ... } ``` -------------------------------- ### Install govalidator Package Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/asaskevich/govalidator/README.md Use 'go get' to install the govalidator package. You can install the latest version or a specific release using gopkg.in. ```bash go get github.com/asaskevich/govalidator or you can get specified release of the package with `gopkg.in`: go get gopkg.in/asaskevich/govalidator.v4 ``` -------------------------------- ### Initialize Procfs and Get Stat Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/prometheus/procfs/README.md Initializes the proc filesystem and retrieves CPU statistics. Use this to start interacting with /proc metrics. ```go fs, err := procfs.NewFS("/proc") stats, err := fs.Stat() ``` -------------------------------- ### SecureJoin Implementation Example (GNU/Linux) Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/cyphar/filepath-securejoin/README.md This example demonstrates a potential implementation of SecureJoin on GNU/Linux using `chroot` and `readlink`. It requires root privileges and assumes `readlink` is within the chroot path. Note that this is for illustrative purposes and the library's implementation is preferred. ```go package securejoin import ( "os/exec" "path/filepath" ) func SecureJoin(root, unsafePath string) (string, error) { unsafePath = string(filepath.Separator) + unsafePath cmd := exec.Command("chroot", root, "readlink", "--canonicalize-missing", "--no-newline", unsafePath) output, err := cmd.CombinedOutput() if err != nil { return "", err } expanded := string(output) return filepath.Join(root, expanded), nil } ``` -------------------------------- ### Install godbus/dbus Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/godbus/dbus/v5/README.md Install the dbus package using the go get command. Requires Go 1.12 or later. ```bash go get github.com/godbus/dbus/v5 ``` -------------------------------- ### Prow Integration Script Example Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/release-tools/README.md Example of a top-level .prow.sh script that sources release-tools/prow.sh and initiates the main Prow process. This is used for Prow end-to-end testing. ```bash #! /bin/bash -e . release-tools/prow.sh main ``` -------------------------------- ### Setup Zap Development Environment Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/go.uber.org/zap/CONTRIBUTING.md Clone the zap repository and set up the upstream remote for development. This is the initial step before making any changes. ```bash mkdir -p $GOPATH/src/go.uber.org cd $GOPATH/src/go.uber.org git clone git@github.com:your_github_username/zap.git cd zap git remote add upstream https://github.com/uber-go/zap.git git fetch upstream ``` -------------------------------- ### Bootstrap and Run E2E Tests on Kubernetes Cluster Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/docs/csi-dev.md Install the NFS CSI Driver on a Kubernetes cluster using `make e2e-bootstrap` and then run the end-to-end tests with `make e2e-test`. Ensure `kubectl get nodes` works from your development machine. ```bash # install NFS CSI Driver on the Kubernetes cluster make e2e-bootstrap # run the E2E test make e2e-test ``` -------------------------------- ### Ginkgo and Gomega Example Spec Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/onsi/ginkgo/v2/README.md This is a comprehensive example demonstrating how to structure tests using Ginkgo's Describe, When, Context, It, BeforeEach, and AfterEach blocks. It also showcases Gomega matchers like Expect, Succeed, ContainElement, Equal, MatchError, BeEmpty, and the use of SpecTimeout and Eventually for asynchronous operations. Ensure Ginkgo and Gomega are imported. ```go import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ... ) var _ = Describe("Checking books out of the library", Label("library"), func() { var library *libraries.Library var book *books.Book var valjean *users.User BeforeEach(func() { library = libraries.NewClient() book = &books.Book{ Title: "Les Miserables", Author: "Victor Hugo", } valjean = users.NewUser("Jean Valjean") }) When("the library has the book in question", func() { BeforeEach(func(ctx SpecContext) { Expect(library.Store(ctx, book)).To(Succeed()) }) Context("and the book is available", func() { It("lends it to the reader", func(ctx SpecContext) { Expect(valjean.Checkout(ctx, library, "Les Miserables")).To(Succeed()) Expect(valjean.Books()).To(ContainElement(book)) Expect(library.UserWithBook(ctx, book)).To(Equal(valjean)) }, SpecTimeout(time.Second * 5)) }) Context("but the book has already been checked out", func() { var javert *users.User BeforeEach(func(ctx SpecContext) { javert = users.NewUser("Javert") Expect(javert.Checkout(ctx, library, "Les Miserables")).To(Succeed()) }) It("tells the user", func(ctx SpecContext) { err := valjean.Checkout(ctx, library, "Les Miserables") Expect(err).To(MatchError("Les Miserables is currently checked out")) }, SpecTimeout(time.Second * 5)) It("lets the user place a hold and get notified later", func(ctx SpecContext) { Expect(valjean.Hold(ctx, library, "Les Miserables")).To(Succeed()) Expect(valjean.Holds(ctx)).To(ContainElement(book)) By("when Javert returns the book") Expect(javert.Return(ctx, library, book)).To(Succeed()) By("it eventually informs Valjean") notification := "Les Miserables is ready for pick up" Eventually(ctx, valjean.Notifications).Should(ContainElement(notification)) Expect(valjean.Checkout(ctx, library, "Les Miserables")).To(Succeed()) Expect(valjean.Books(ctx)).To(ContainElement(book)) Expect(valjean.Holds(ctx)).To(BeEmpty()) }, SpecTimeout(time.Second * 10)) }) }) When("the library does not have the book in question", func() { It("tells the reader the book is unavailable", func(ctx SpecContext) { err := valjean.Checkout(ctx, library, "Les Miserables") Expect(err).To(MatchError("Les Miserables is not in the library catalog")) }, SpecTimeout(time.Second * 5)) }) }) ``` -------------------------------- ### Install NFS CSI Driver Locally Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/docs/install-csi-driver-v4.13.3.md Clone the repository and execute the local installation script to install the NFS CSI driver. This method requires the driver's source code to be present locally. ```bash git clone https://github.com/kubernetes-csi/csi-driver-nfs.git cd csi-driver-nfs ./deploy/install-driver.sh v4.13.3 local ``` -------------------------------- ### Install gRPC-Go Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/google.golang.org/grpc/README.md Add this import to your Go code to automatically fetch gRPC-Go dependencies during build, run, or test commands. ```go import "google.golang.org/grpc" ``` -------------------------------- ### Import gofuzz Library Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/google/gofuzz/README.md Import the gofuzz library to start using its functionalities. ```go import "github.com/google/gofuzz" ``` -------------------------------- ### Get OpenTelemetry Go with go get Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md This command fetches the OpenTelemetry Go project into your GOPATH. Ignore any build constraint warnings. ```go go get -d go.opentelemetry.io/otel ``` -------------------------------- ### Example Output of Pod Status Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/docs/install-csi-driver-v4.13.3.md This is an example of the expected output when checking the status of NFS CSI driver pods. ```console NAME READY STATUS RESTARTS AGE IP NODE csi-nfs-controller-56bfddd689-dh5tk 4/4 Running 0 35s 10.240.0.19 k8s-agentpool-22533604-0 csi-nfs-node-cvgbs 3/3 Running 0 35s 10.240.0.35 k8s-agentpool-22533604-1 csi-nfs-node-dr4s4 3/3 Running 0 35s 10.240.0.4 k8s-agentpool-22533604-0 ``` -------------------------------- ### Install CSI Driver NFS with Custom Values Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/charts/README.md Install the CSI Driver NFS chart using Helm, applying custom configurations from a specified values file. ```console helm install csi-driver-nfs csi-driver-nfs/csi-driver-nfs --namespace kube-system -f custom-values.yaml ``` -------------------------------- ### Verify NFS Mount in Pod Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/deploy/example/nfs-provisioner/README.md Execute this command within the example pod to check if the NFS share is correctly mounted. ```bash kubectl exec nginx-nfs-example -- bash -c "findmnt /var/www -o TARGET,SOURCE,FSTYPE" ``` -------------------------------- ### Check Source PVC Data Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/deploy/example/snapshot/README.md Exec into the example pod to verify that data has been written to the mounted NFS volume. ```bash $ kubectl exec nginx-nfs -- ls /mnt/nfs outfile ``` -------------------------------- ### Add or Update Dependencies Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/prometheus/procfs/CONTRIBUTING.md Use 'go get' to fetch the latest or a specific version of an external module. This command updates the project's dependencies. ```bash # Pick the latest tagged release. go get example.com/some/module/pkg # Pick a specific version. go get example.com/some/module/pkg@vX.Y.Z ``` -------------------------------- ### SpdyStream Server Example Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/moby/spdystream/README.md Demonstrates how to set up a SpdyStream server that listens for incoming TCP connections and serves incoming streams using a mirroring handler. This server will echo back any data received on a stream. ```go package main import ( "github.com/moby/spdystream" "net" ) func main() { listener, err := net.Listen("tcp", "localhost:8080") if err != nil { panic(err) } for { conn, err := listener.Accept() if err != nil { panic(err) } spdyConn, err := spdystream.NewConnection(conn, true) if err != nil { panic(err) } go spdyConn.Serve(spdystream.MirrorStreamHandler) } } ``` -------------------------------- ### SpdyStream Client Example Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/moby/spdystream/README.md Demonstrates how to connect to a SpdyStream server, create a new stream, write data to it, read data back, and close the stream. Requires a running mirroring server on localhost:8080. ```go package main import ( "fmt" "github.com/moby/spdystream" "net" "net/http" ) func main() { conn, err := net.Dial("tcp", "localhost:8080") if err != nil { panic(err) } spdyConn, err := spdystream.NewConnection(conn, false) if err != nil { panic(err) } go spdyConn.Serve(spdystream.NoOpStreamHandler) stream, err := spdyConn.CreateStream(http.Header{}, nil, false) if err != nil { panic(err) } stream.Wait() fmt.Fprint(stream, "Writing to stream") buf := make([]byte, 25) stream.Read(buf) fmt.Println(string(buf)) stream.Close() } ``` -------------------------------- ### Get and Set Interface{} Value with reflect2 Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/modern-go/reflect2/README.md To get and set values of an interface{}, always use its pointer type. This example demonstrates setting the value of 'i' to 'j' using reflect2. ```go valType := reflect2.TypeOf(1) i := 1 j := 10 valType.Set(&i, &j) // i will be 10 ``` -------------------------------- ### Install Latest JSON-Patch Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/gopkg.in/evanphx/json-patch.v4/README.md Use this command to get the latest version of the json-patch library. ```bash go get -u github.com/evanphx/json-patch/v5 ``` -------------------------------- ### Get and Set unsafe.Pointer Value with reflect2 Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/modern-go/reflect2/README.md Similar to interface{}, to get and set values using unsafe.Pointer, always use its pointer type. This example shows setting the value pointed to by 'i' to the value pointed to by 'j'. ```go valType := reflect2.TypeOf(1) i := 1 j := 10 valType.UnsafeSet(unsafe.Pointer(&i), unsafe.Pointer(&j)) // i will be 10 ``` -------------------------------- ### Create New Configuration with Options Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Wraps default settings and applies provided options to create a configured struct. Validation can be included, returning an error if necessary. This function is typically unexported. ```go // newConfig returns an appropriately configured config. func newConfig(options ...Option) config { // Set default values for config. config := config{/* […] */} for _, option := range options { config = option.apply(config) } // Perform any validation here. return config } ``` -------------------------------- ### Deploy Sample Pod for NFS Testing Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/deploy/example/nfs-provisioner/README.md Create a sample pod to test the NFS server functionality by statically creating a PersistentVolume and PersistentVolumeClaim. ```bash kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/example/nfs-provisioner/nginx-pod.yaml ``` -------------------------------- ### Coexist with glog Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/k8s.io/klog/v2/README.md Example demonstrating how to initialize and synchronize flags between klog and glog. It also shows how to use stderr for combined output by setting 'alsologtostderr' or 'logtostderr' to true. ```go package main import ( "flag" "os" "k8s.io/klog/v2" "github.com/golang/glog" ) func main() { // Initialize klog flags klog.InitFlags(nil) // Initialize glog flags flag.Parse() // Set glog to log to stderr flag.Set("logtostderr", "true") // Set klog to log to stderr klog.SetOutput(os.Stderr) klog.Info("klog message") glog.Info("glog message") } ``` -------------------------------- ### Install NFS CSI Driver Remotely Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/docs/install-csi-driver-v4.13.3.md Use this command to install the NFS CSI driver by downloading the installation script remotely. Ensure you specify the desired version. ```bash curl -skSL https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/v4.13.3/deploy/install-driver.sh | bash -s v4.13.3 -- ``` -------------------------------- ### Enable fsGroupPolicy via Helm Installation Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/deploy/example/fsgroup/README.md Add this flag to your Helm installation command to enable fsGroupPolicy support when installing or upgrading the NFS CSI driver chart. ```bash --set feature.enableFSGroupPolicy=true ``` -------------------------------- ### New Function Signature with Options Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Demonstrates the signature for a constructor function that accepts variadic options. Required parameters should precede the options. ```go func NewT(options ...Option) T {…} ``` -------------------------------- ### Create Source NFS PVC and Pod Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/deploy/example/cloning/README.md Apply the StorageClass, dynamic NFS PVC, and a pod to create the initial NFS volume. Ensure the NFS CSI driver is installed and configured. ```bash kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/example/storageclass-nfs.yaml kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/example/pvc-nfs-csi-dynamic.yaml kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/example/nginx-pod-nfs.yaml ``` -------------------------------- ### Install Stable JSON-Patch Versions Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/gopkg.in/evanphx/json-patch.v4/README.md Commands to install specific stable versions of the json-patch library. ```bash go get -u gopkg.in/evanphx/json-patch.v5 ``` ```bash go get -u gopkg.in/evanphx/json-patch.v4 ``` -------------------------------- ### Basic fsnotify Watcher Usage in Go Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/fsnotify/fsnotify/README.md Demonstrates how to create a new watcher, listen for events and errors in a goroutine, and add a directory to watch. Ensure to handle errors and close the watcher when done. ```go package main import ( "log" "github.com/fsnotify/fsnotify" ) func main() { // Create new watcher. watcher, err := fsnotify.NewWatcher() if err != nil { log.Fatal(err) } defer watcher.Close() // Start listening for events. go func() { for { select { case event, ok := <-watcher.Events: if !ok { return } log.Println("event:", event) if event.Has(fsnotify.Write) { log.Println("modified file:", event.Name) } case err, ok := <-watcher.Errors: if !ok { return } log.Println("error:", err) } } }() // Add a path. err = watcher.Add("/tmp") if err != nil { log.Fatal(err) } // Block main goroutine forever. <-make(chan struct{}) } ``` -------------------------------- ### Add Helm Repository and Install CSI NFS Driver Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/charts/README.md Adds the CSI NFS driver Helm repository and installs the driver in the kube-system namespace. Specify the --version flag to install a particular chart version. ```console helm repo add csi-driver-nfs https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/charts helm install csi-driver-nfs csi-driver-nfs/csi-driver-nfs --namespace kube-system --version 4.12.0 ``` -------------------------------- ### Initialize and Use Framework Instance in Ginkgo Tests Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/k8s.io/kubernetes/test/e2e/framework/README.md Demonstrates how to initialize a `Framework` instance using `NewDefaultFramework` within a Ginkgo test suite. The `AfterEach` callback can be used for cleanup operations involving the `Framework`'s `ClientSet`. The `It` block contains the actual test logic. ```go f := framework.NewDefaultFramework("some tests") ginkgo.AfterEach(func() { # Do something with f.ClientSet. }) ginkgo.It("test something", func(ctx context.Context) { # The actual test. }) ``` -------------------------------- ### Install Cobra CLI Generator Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/spf13/cobra/README.md Install the 'cobra-cli' command line program to generate Cobra application scaffolding. ```bash go install github.com/spf13/cobra-cli@latest ``` -------------------------------- ### OpenInRoot vs. Standard OpenFile Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/cyphar/filepath-securejoin/README.md Illustrates the safer approach to opening files using OpenInRoot compared to the standard os.OpenFile with a potentially insecurely joined path. OpenInRoot prevents race attacks. ```go path, err := securejoin.SecureJoin(root, unsafePath) file, err := os.OpenFile(path, unix.O_PATH|unix.O_CLOEXEC) ``` -------------------------------- ### String Substring Function Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/google/cel-go/ext/README.md Extracts a substring based on character positions. Supports a single argument for the start index to the end of the string, or two arguments for a start (inclusive) and end (exclusive) range. Negative indices or an end range lower than the start range will result in an error. ```cel 'tacocat'.substring(4) ``` ```cel 'tacocat'.substring(0, 4) ``` ```cel 'tacocat'.substring(-1) ``` ```cel 'tacocat'.substring(2, 1) ``` -------------------------------- ### Prepare and Commit Changes Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Create a new branch, make your modifications, run precommit checks, stage changes, commit, and push to your fork. ```sh git checkout -b # edit files # update changelog make precommit git add -p git commit git push ``` -------------------------------- ### Extract a Sub-list Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/google/cel-go/ext/README.md The `.slice(start, end)` method returns a new list containing elements from the `start` index up to (but not including) the `end` index. ```cel [1,2,3,4].slice(1, 3) // return [2, 3] ``` ```cel [1,2,3,4].slice(2, 4) // return [3, 4] ``` -------------------------------- ### Convert Dep to Go Modules Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/release-tools/README.md Commands to initialize Go modules, fetch Kubernetes dependencies, tidy, and vendor, then clean up old `dep` files. ```bash GO111MODULE=on go mod init release-tools/go-get-kubernetes.sh GO111MODULE=on go mod tidy GO111MODULE=on go mod vendor git rm -f Gopkg.toml Gopkg.lock git add go.mod go.sum vendor ``` -------------------------------- ### Create NFS Provisioner (Linux/arm) Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/deploy/example/nfs-provisioner/README.md Follow these steps to build and deploy an NFS provisioner for Linux ARM architecture. Ensure you replace `` with your Docker Hub username. ```bash git clone https://github.com/sjiveson/nfs-server-alpine.git cd nfs-server-alpine docker build -t /nfs-server-alpine:latest-arm . wget https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/example/nfs-provisioner/nfs-server.yaml sed -i 's//itsthenetwork/' nfs-server.yaml kubectl create -f nfs-server.yaml ``` -------------------------------- ### Install Gomega Plugin for Claude Code Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/onsi/gomega/README.md Install the Gomega plugin for Claude Code to enable Gomega's idioms and matchers within your agent's assertions. This can be done interactively or non-interactively. ```bash /plugin marketplace add onsi/gomega /plugin install gomega@gomega ``` ```bash claude plugin marketplace add onsi/gomega claude plugin install gomega@gomega ``` -------------------------------- ### Start NFS CSI Driver Locally Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/docs/csi-dev.md Start the NFS CSI driver in a local environment. This command runs the driver as a background process, exposing a CSI endpoint via a Unix domain socket. ```console $ cd $GOPATH/src/github.com/kubernetes-csi/csi-driver-nfs $ ./bin/nfsplugin --endpoint unix:///tmp/csi.sock --nodeid CSINode -v=5 & ``` -------------------------------- ### Preview Ginkgo Documentation Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/onsi/ginkgo/v2/CONTRIBUTING.md Builds and serves the Ginkgo documentation locally using Jekyll. This allows you to preview your documentation changes before committing. ```bash bundle && bundle exec jekyll serve ``` -------------------------------- ### Create Root Logger Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/go-logr/logr/README.md Initialize the root logger with a chosen implementation and parameters early in the application's lifecycle. ```go func main() { // ... other setup code ... // Create the "root" logger. We have chosen the "logimpl" implementation, // which takes some initial parameters and returns a logr.Logger. logger := logimpl.New(param1, param2) // ... other setup code ... } ``` -------------------------------- ### Prometheus Histogram Metrics Example Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/grpc-ecosystem/go-grpc-prometheus/README.md Example output of Prometheus histogram metrics for server handling seconds, including count, sum, and bucket values. These metrics provide detailed insights into RPC latency distributions. ```prometheus grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="0.005"} 1 grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="0.01"} 1 grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="0.025"} 1 grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="0.05"} 1 grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="0.1"} 1 grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="0.25"} 1 grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="0.5"} 1 grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="1"} 1 grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="2.5"} 1 grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="5"} 1 grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="10"} 1 grpc_server_handling_seconds_bucket{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream",le="+Inf"} 1 grpc_server_handling_seconds_sum{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream"} 0.0003866430000000001 grpc_server_handling_seconds_count{grpc_code="OK",grpc_method="PingList",grpc_service="mwitkow.testproto.TestService",grpc_type="server_stream"} 1 ``` -------------------------------- ### Install CSI NFS Driver with Custom Names Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/charts/README.md Installs the CSI NFS driver with a customized driver name and deployment names. This feature is supported from version v3.1.0 onwards. Ensure all specified service accounts and names are unique. ```console helm install csi-driver-nfs2 csi-driver-nfs/csi-driver-nfs --namespace kube-system --set driver.name="nfs2.csi.k8s.io" --set controller.name="csi-nfs2-controller" --set rbac.name=nfs2 --set serviceAccount.controller=csi-nfs2-controller-sa --set serviceAccount.node=csi-nfs2-node-sa --set node.name=csi-nfs2-node --set node.livenessProbe.healthPort=39653 ``` -------------------------------- ### Basic Usage of gziphandler Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/NYTimes/gziphandler/README.md Wrap an existing http.Handler with gziphandler.GzipHandler to enable transparent gzip compression for supported clients. This example demonstrates setting up a simple HTTP server with gzip compression enabled. ```go package main import ( io "io" "net/http" "github.com/NYTimes/gziphandler" ) func main() { withoutGz := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") io.WriteString(w, "Hello, World") }) withGz := gziphandler.GzipHandler(withoutGz) http.Handle("/", withGz) http.ListenAndServe("0.0.0.0:8000", nil) } ``` -------------------------------- ### Create PersistentVolume and PersistentVolumeClaim Statically Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/deploy/example/README.md Manually create a PersistentVolume and PersistentVolumeClaim for static provisioning. This requires pre-existing NFS shares. ```bash # create PV kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/example/pv-nfs-csi.yaml # create PVC kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/deploy/example/pvc-nfs-csi-static.yaml ``` -------------------------------- ### Expected NFS Mount Output Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/deploy/example/nfs-provisioner/README.md This is the expected output when verifying the NFS mount point from the example pod. ```text TARGET SOURCE FSTYPE /var/www nfs-server.default.svc.cluster.local:/ nfs4 ``` -------------------------------- ### Run Go Benchmarks Source: https://github.com/kubernetes-csi/csi-driver-nfs/blob/master/vendor/github.com/go-openapi/swag/BENCHMARK.md Use this command to execute benchmarks for the go-openapi/swag library. Specify the benchmark and test patterns with -bench and -run flags, and set the benchmark duration with -benchtime. ```bash go test -bench XXX -run XXX -benchtime 30s ```