### Basic WebService Setup and Route Definition in go-restful Source: https://github.com/sgl-project/rbg/blob/main/vendor/github.com/emicklei/go-restful/v3/README.md This example illustrates the basic setup of a WebService in go-restful. It defines the path, supported content types (consumes/produces), and a GET route for retrieving a user. The route is mapped to the `findUser` function and includes documentation and parameter definitions. ```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 Diskv using Go Get Source: https://github.com/sgl-project/rbg/blob/main/vendor/github.com/peterbourgon/diskv/README.md This snippet shows the command to install the diskv library using Go's package management tool. It requires Go 1.x to be installed. ```bash go get github.com/peterbourgon/diskv ``` -------------------------------- ### Install and Run Local Go Doc Site Source: https://github.com/sgl-project/rbg/blob/main/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Installs and runs a local Go Doc site using pkgsite. This tool helps in previewing package documentation locally before publishing. ```shell go install golang.org/x/pkgsite/cmd/pkgsite@latest ``` ```shell pkgsite ``` -------------------------------- ### Example Old RBG Configuration (YAML) Source: https://github.com/sgl-project/rbg/blob/main/keps/133-configmap-refine/README.md An example illustrating the old YAML configuration format for an RBG setup with multiple roles and instances. ```yaml group: name: epd-test roles: - router - encoder - prefill - decode size: 4 roles: decode: instances: - address: decode-0.s-epd-test-decode - address: decode-1.s-epd-test-decode size: 2 encoder: instances: - address: encoder-0.s-epd-test-encoder - address: encoder-1.s-epd-test-encoder size: 2 prefill: instances: - address: prefill-0.s-epd-test-prefill - address: prefill-1.s-epd-test-prefill size: 2 router: instances: - address: router-0.s-epd-test-router size: 1 ``` -------------------------------- ### Example New RBG Configuration (YAML) Source: https://github.com/sgl-project/rbg/blob/main/keps/133-configmap-refine/README.md An example demonstrating the new YAML configuration format, including namespace, replicas, size, and an example of excluding a role index. ```yaml namespace: sgl-workspace group: epd-test roles: router: replicas: 1 size: 1 encoder: replicas: 2 size: 2 prefill: replicas: 3 # three replicas size: 2 # each replica has 2 pods decode: replicas: 2 # two replicas, but role index 1 is excluded, so only decode-0 is included excludes: [1] # Optional, exist when rolling update or scaling down size: 4 # each replica has 4 pods ``` -------------------------------- ### Clone zap Repository and Setup Source: https://github.com/sgl-project/rbg/blob/main/vendor/go.uber.org/zap/CONTRIBUTING.md This snippet demonstrates how to clone the zap repository from GitHub, set up the remote upstream, and fetch the latest changes. It assumes you have Go installed and your GOPATH configured. ```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 ``` -------------------------------- ### Application Logging Setup with logr.Logger Source: https://github.com/sgl-project/rbg/blob/main/vendor/github.com/go-logr/logr/README.md Demonstrates the typical initialization of a root logger in a Go application using a logr implementation. This setup is done 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 ... } ``` -------------------------------- ### Bash: Install and Setup envtest Binaries Source: https://github.com/sgl-project/rbg/blob/main/test/envtest/README.md This bash command installs the `setup-envtest` tool and exports the necessary `KUBEBUILDER_ASSETS` environment variable, which is required for running Kubernetes integration tests. ```bash export KUBEBUILDER_ASSETS="$(setup-envtest use -p path)" ``` -------------------------------- ### Install go-gitignore Library (Shell) Source: https://github.com/sgl-project/rbg/blob/main/vendor/github.com/monochromegane/go-gitignore/README.md Provides the command to install the go-gitignore library using the Go build tools. This command fetches the library and makes it available for use in your Go projects. ```sh go get github.com/monochromegane/go-gitignore ``` -------------------------------- ### SpdyStream Server Example (Go) Source: https://github.com/sgl-project/rbg/blob/main/vendor/github.com/moby/spdystream/README.md Provides an example of a SPDY server that listens for incoming TCP connections and mirrors any streams created by clients. It utilizes the 'github.com/moby/spdystream' package. ```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) } } ``` -------------------------------- ### Install kubectl-rbg Plugin Source: https://github.com/sgl-project/rbg/blob/main/doc/features/kubectl-rbg-benchmark.md Installs the kubectl-rbg plugin by cloning the repository, building the CLI, making it executable, and moving it to the system's PATH. ```bash git clone https://github.com/sgl-project/rbg.git make build-cli chmod +x bin/kubectl-rbg sudo mv bin/kubectl-rbg /usr/local/bin/ ``` -------------------------------- ### Install jsonpatch Go Library Source: https://github.com/sgl-project/rbg/blob/main/vendor/github.com/evanphx/json-patch/README.md Instructions for installing the jsonpatch library using the Go build tool. It provides commands for the latest version and stable releases (v5 and v4). ```bash go get -u github.com/evanphx/json-patch/v5 go get -u gopkg.in/evanphx/json-patch.v5 go get -u gopkg.in/evanphx/json-patch.v4 ``` -------------------------------- ### Example: Using TagSet and TagOptions for CBOR Decoding/Encoding (Go) Source: https://github.com/sgl-project/rbg/blob/main/vendor/github.com/fxamacker/cbor/v2/README.md Provides a comprehensive example of using TagSet and TagOptions in the fxamacker/cbor library to register custom types for specific CBOR tags. It shows how to create a DecMode for unmarshaling and an EncMode for marshaling data with custom tag support. ```go // Use signedCWT struct defined in "Decoding CWT" example. // Create TagSet (safe for concurrency). tags := cbor.NewTagSet() // Register tag COSE_Sign1 18 with signedCWT type. tags.Add( cbor.TagOptions{EncTag: cbor.EncTagRequired, DecTag: cbor.DecTagRequired}, reflect.TypeOf(signedCWT{}), 18) // Create DecMode with immutable tags. dm, _ := cbor.DecOptions{}.DecModeWithTags(tags) // Unmarshal to signedCWT with tag support. var v signedCWT if err := dm.Unmarshal(data, &v); err != nil { return err } // Create EncMode with immutable tags. em, _ := cbor.EncOptions{}.EncModeWithTags(tags) // Marshal signedCWT with tag number. if data, err := em.Marshal(v); err != nil { return err } ``` -------------------------------- ### Install and Use setup-envtest Tool Source: https://github.com/sgl-project/rbg/blob/main/test/envtest/README.md Installs the setup-envtest tool and its required Kubernetes test binaries. It also shows how to set the KUBEBUILDER_ASSETS environment variable, which is crucial for running envtest. ```bash # Install setup-envtest go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest # Install test binaries setup-envtest use -p path # Set environment variable (add to shell profile or run before tests) export KUBEBUILDER_ASSETS="$(setup-envtest use -p path)" ``` ```bash make envtest ``` -------------------------------- ### Install json-iterator/go (Go) Source: https://github.com/sgl-project/rbg/blob/main/vendor/github.com/json-iterator/go/README.md This command shows how to install the json-iterator/go library using the Go build tools. This is the standard method for adding external Go packages to your project. ```Shell go get github.com/json-iterator/go ``` -------------------------------- ### Remote Debugging Setup with Delve Source: https://github.com/sgl-project/rbg/blob/main/doc/dev/how_to_develop.md Configures Delve for remote debugging. The first command starts the debugger in headless mode on the remote host, listening on a specified port. The second command connects the local debugger to the remote instance. ```shell # On remote host: dlv debug --headless --listen ":12345" --log --api-version=2 cmd/rbgs/main.go # On local machine: dlv connect ":12345" --api-version=2 ``` -------------------------------- ### Run Patio Server Locally Source: https://github.com/sgl-project/rbg/blob/main/python/patio/doc/examples.md Command to navigate to the Python project directory and run the Patio server application locally. Assumes the project structure includes a 'python' subdirectory. ```bash cd /python python -m patio.app ``` -------------------------------- ### Local Debugging with Delve Command Line Source: https://github.com/sgl-project/rbg/blob/main/doc/dev/how_to_develop.md Initiates a local debugging session for the RBG project using the Delve debugger. Ensure 'go help' is installed. This command starts the debugger attached to the main entry point of the application. ```shell dlv debug cmd/rbgs/main.go ``` -------------------------------- ### Quick Start: Logger for Performance-Critical Logging in Go Source: https://github.com/sgl-project/rbg/blob/main/vendor/go.uber.org/zap/README.md Illustrates the usage of the base Logger for performance-critical scenarios where type safety is paramount. This logger is faster and allocates less than SugaredLogger, exclusively supporting structured logging. ```go logger, _ := zap.NewProduction() deferr logger.Sync() logger.Info("failed to fetch URL", // Structured context as strongly typed Field values. zap.String("url", url), zap.Int("attempt", 3), zap.Duration("backoff", time.Second) ) ``` -------------------------------- ### Quick Start: SugaredLogger for Production Logging in Go Source: https://github.com/sgl-project/rbg/blob/main/vendor/go.uber.org/zap/README.md Demonstrates how to initialize and use the SugaredLogger for production environments. This logger offers both structured and printf-style logging, prioritizing performance over strict type safety. ```go logger, _ := zap.NewProduction() deferr logger.Sync() // flushes buffer, if any sugar := logger.Sugar() sugar.Infow("failed to fetch URL", // Structured context as loosely typed key-value pairs. "url", url, "attempt", 3, "backoff", time.Second, ) sugar.Infof("Failed to fetch URL: %s", url) ``` -------------------------------- ### Install and Deploy RBG CRDs and Controller (Shell) Source: https://github.com/sgl-project/rbg/blob/main/doc/dev/how_to_develop.md This set of shell commands is used to install the Custom Resource Definitions (CRDs) for RBGs and then deploy the RBG controller to your Kubernetes cluster. It includes commands to verify the installation. ```shell make install # Check CRD with: $ kubectl get crd | grep -e rolebasedgroup -e clusterengineruntimeprofiles make deploy # Check rbg system with: $ kubectl get po -n rbgs-system ``` -------------------------------- ### Initializing and Naming Loggers in Go Source: https://github.com/sgl-project/rbg/blob/main/vendor/sigs.k8s.io/controller-runtime/TMP-LOGGING.md Illustrates how to obtain the root logger, create named loggers using `WithName`, and add contextual values using `WithValues` in Go. This allows for hierarchical and contextual logging. ```go logger := log.Log.WithName("controller").WithName("replicaset") // in reconcile... logger = logger.WithValues("replicaset", req.NamespacedName) // later on in reconcile... logger.Info("doing things with pods", "pod", newPod) ``` -------------------------------- ### Install Cobra Library Source: https://github.com/sgl-project/rbg/blob/main/vendor/github.com/spf13/cobra/README.md Installs the latest version of the Cobra library using the Go get command. This is the first step to include Cobra in your Go project. ```bash go get -u github.com/spf13/cobra@latest ``` -------------------------------- ### SpdyStream Client Example (Go) Source: https://github.com/sgl-project/rbg/blob/main/vendor/github.com/moby/spdystream/README.md Demonstrates how to establish a client connection to a SPDY server, create a stream, write data to it, read data back, and close the stream. Requires the 'github.com/moby/spdystream' package. ```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() } ``` -------------------------------- ### Install jsonpatch Go Package Source: https://github.com/sgl-project/rbg/blob/main/vendor/github.com/appscode/jsonpatch/README.md Command to install the jsonpatch Go package using the go get command. This is the primary way to include the library in your Go projects. ```console go get github.com/appscode/jsonpatch ``` -------------------------------- ### Initialize Gitignore from io.Reader (Go) Source: https://github.com/sgl-project/rbg/blob/main/vendor/github.com/monochromegane/go-gitignore/README.md Shows how to initialize the Gitignore library using an io.Reader. This method is flexible, allowing gitignore content to be read from various sources like strings or network connections. It requires a base directory and the reader containing the gitignore rules. ```go gitignore, _ := gitignore.NewGitIgnoreFromReader(base, reader) ``` -------------------------------- ### Install Cobra CLI Generator Source: https://github.com/sgl-project/rbg/blob/main/vendor/github.com/spf13/cobra/README.md Installs the cobra-cli command-line tool, which helps bootstrap Cobra applications and generate command files. This tool simplifies the initial setup of a Cobra-based application. ```bash go install github.com/spf13/cobra-cli@latest ``` -------------------------------- ### YAML: GitHub Actions Setup for envtest Source: https://github.com/sgl-project/rbg/blob/main/test/envtest/README.md This YAML snippet configures a GitHub Actions workflow to set up `envtest` by installing the tool and setting the `KUBEBUILDER_ASSETS` environment variable. ```yaml # GitHub Actions example - name: Setup envtest run: | go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest echo "KUBEBUILDER_ASSETS=$(setup-envtest use -p path)" >> $GITHUB_ENV - name: Run envtest run: | make test-envtest ``` -------------------------------- ### Initialize Gitignore with Base Directory (Go) Source: https://github.com/sgl-project/rbg/blob/main/vendor/github.com/monochromegane/go-gitignore/README.md Demonstrates how to initialize the Gitignore library by specifying a base directory. This is useful when the gitignore file is not in the root of the project or when dealing with global gitignore files. The second argument to NewGitIgnore sets the base directory. ```go gitignore, _ := gitignore.NewGitIgnore("/home/you/.gitignore", ".") ``` -------------------------------- ### Basic Logging with glog in Go Source: https://github.com/sgl-project/rbg/blob/main/vendor/k8s.io/klog/v2/README.md Demonstrates basic logging operations using the glog package in Go. This includes simple informational messages and fatal error logging, which terminates the program. ```Go import "github.com/golang/glog" func main() { glog.Info("Prepare to repel boarders") // Example of fatal error logging, which will terminate the program // err := someFunctionThatMightFail() // if err != nil { // glog.Fatalf("Initialization failed: %s", err) // } } ``` -------------------------------- ### Multi-node Inference Deployment with LeaderWorkerSet Source: https://github.com/sgl-project/rbg/blob/main/keps/8-reduce-yaml-duplication/README.md This example illustrates a multi-node inference setup using the RoleBasedGroup API integrated with LeaderWorkerSet. The `roleTemplate` defines shared configurations, `role.templatePatch` adds role-specific settings, and `patchLeaderTemplate`/`patchWorkerTemplate` customize distributed commands for leader and worker nodes. This enables scalable inference across multiple machines. ```yaml apiVersion: workloads.x-k8s.io/v1alpha1 kind: RoleBasedGroup metadata: name: sglang-multi-node spec: roleTemplates: - name: sglang-base template: spec: volumes: - name: model persistentVolumeClaim: claimName: llm-model - name: dshm emptyDir: medium: Memory sizeLimit: 15Gi containers: - name: sglang image: sglang:v0.5.1 volumeMounts: - mountPath: /models/Qwen3-32B name: model - mountPath: /dev/shm name: dshm resources: limits: nvidia.com/gpu: "1" memory: "48Gi" roles: - name: inference replicas: 1 templateRef: name: sglang-base templatePatch: spec: containers: - name: sglang env: - name: MODEL value: Qwen3-32B workload: apiVersion: leaderworkerset.x-k8s.io/v1 kind: LeaderWorkerSet leaderWorkerSet: size: 2 patchLeaderTemplate: spec: containers: - name: sglang command: - sh - -c - "python3 -m sglang.launch_server --model-path /models/Qwen3-32B --tp 2 --dist-init-addr $(LWS_LEADER_ADDRESS):20000 --nnodes $(LWS_GROUP_SIZE) --node-rank $(LWS_WORKER_INDEX) --host 0.0.0.0 --port 8000" ports: - containerPort: 8000 readinessProbe: tcpSocket: port: 8000 patchWorkerTemplate: spec: containers: - name: sglang command: - sh - -c - "python3 -m sglang.launch_server --model-path /models/Qwen3-32B --tp 2 --dist-init-addr $(LWS_LEADER_ADDRESS):20000 --nnodes $(LWS_GROUP_SIZE) --node-rank $(LWS_WORKER_INDEX)" ``` -------------------------------- ### Initialize Gitignore from Path and Match File (Go) Source: https://github.com/sgl-project/rbg/blob/main/vendor/github.com/monochromegane/go-gitignore/README.md Initializes a new Gitignore instance from a specified gitignore file path and then matches a given file path against the loaded rules. It returns a Gitignore object and an error if initialization fails. The Match function takes the file path and a boolean indicating if it's a directory. ```go gitignore, _ := gitignore.NewGitIgnore("/path/to/gitignore") path := "/path/to/file" isDir := false gitignore.Match(path, isDir) ``` -------------------------------- ### Basic Structured Logging in Go Source: https://github.com/sgl-project/rbg/blob/main/vendor/sigs.k8s.io/controller-runtime/TMP-LOGGING.md Demonstrates the difference between standard library logging and structured logging in controller-runtime. Structured logging separates the log message from variable key-value pairs for better organization and searchability. ```go log.Printf("starting reconciliation for pod %s/%s", podNamespace, podName) ``` ```go logger.Info("starting reconciliation", "pod", req.NamespacedName) ``` -------------------------------- ### Install aiconfigurator with Pip Source: https://github.com/sgl-project/rbg/blob/main/doc/features/kubectl-rbg-llm-generate.md This text snippet provides instructions for installing the 'aiconfigurator' package. It suggests using pip, a common Python package installer, and provides a link to the project's GitHub repository for more information. ```text Error: aiconfigurator is not installed Please install it using one of the following methods: pip install aiconfigurator Or visit: https://github.com/ai-dynamo/aiconfigurator ``` -------------------------------- ### Verify aiconfigurator Installation Source: https://github.com/sgl-project/rbg/blob/main/doc/features/kubectl-rbg-llm-generate.md Checks the installed version of aiconfigurator. Ensure the version is 0.5.0 or higher for compatibility. ```bash aiconfigurator version # version >= 0.5.0 ``` -------------------------------- ### Install RBG Controller via kubectl Source: https://context7.com/sgl-project/rbg/llms.txt Installs the RBG controller manager and CRDs into a Kubernetes cluster using kubectl. Requires Kubernetes version 1.28 or higher. It applies manifests, waits for the controller to be available, and verifies the installation by checking for CRD presence. ```bash # Prerequisites: Kubernetes cluster version >= 1.28 # Install RBG using kubectl kubectl apply --server-side -f ./deploy/kubectl/manifests.yaml # Wait for the controller to be ready kubectl wait deploy/rbgs-controller-manager -n rbgs-system --for=condition=available --timeout=5m # Verify installation kubectl get crds | grep rolebasedgroup # Expected output: # rolebasedgroups.workloads.x-k8s.io # rolebasedgroupsets.workloads.x-k8s.io # instances.workloads.x-k8s.io # instancesets.workloads.x-k8s.io ``` -------------------------------- ### Run golangci-lint from the command line Source: https://github.com/sgl-project/rbg/blob/main/vendor/github.com/Microsoft/go-winio/README.md This shell command demonstrates how to run the golangci-lint tool from the repository root. It can lint all packages in the current directory and its subdirectories (`./...`). Flags are available to control the verbosity of the output, such as showing all lint errors. ```shell # use . or specify a path to only lint a package # to show all lint errors, use flags "--max-issues-per-linter=0 --max-same-issues=0" > golangci-lint run ./... ``` -------------------------------- ### Install aiconfigurator Source: https://github.com/sgl-project/rbg/blob/main/doc/features/kubectl-rbg-llm-generate.md Installs the aiconfigurator Python package using pip. This is a prerequisite for using the `kubectl-rbg llm generate` command. ```bash pip install aiconfigurator ``` -------------------------------- ### Run Tests with Go Source: https://github.com/sgl-project/rbg/blob/main/vendor/gopkg.in/evanphx/json-patch.v4/README.md This command executes all tests within the current Go module and reports code coverage. Ensure you have Go installed and are in the project's root directory. ```bash go test -cover ./... ``` -------------------------------- ### Verify setup-envtest Installation Source: https://github.com/sgl-project/rbg/blob/main/test/envtest/README.md Verifies that the setup-envtest tool has been installed correctly and that the necessary Kubernetes test binaries are available in the specified path. ```bash # Check envtest binary path setup-envtest use -p path # Verify binaries exist ls $(setup-envtest use -p path) # Should see: etcd kube-apiserver kubectl ``` -------------------------------- ### Create and Log Nested Traces (Go) Source: https://github.com/sgl-project/rbg/blob/main/vendor/k8s.io/utils/trace/README.md Demonstrates how to create nested traces, allowing for hierarchical performance monitoring. A root trace is created, and then a nested trace is initiated within it, each with its own logging threshold. ```Go func doSomething() { rootTrace := trace.New("rootOperation") defer rootTrace.LogIfLong(100 * time.Millisecond) func() { nestedTrace := rootTrace.Nest("nested", Field{Key: "nestedFieldKey1", Value: "nestedFieldValue1"}) defer nestedTrace.LogIfLong(50 * time.Millisecond) // do nested operation }() } ``` -------------------------------- ### Ginkgo Spec Example: Library Checkout Source: https://github.com/sgl-project/rbg/blob/main/vendor/github.com/onsi/ginkgo/v2/README.md This Go code snippet demonstrates a typical Ginkgo test suite for a library checkout scenario. It uses Ginkgo's `Describe`, `When`, `Context`, `It`, `BeforeEach`, and `AfterEach` constructs to define test cases and setup/teardown logic. It also utilizes Gomega matchers like `Expect`, `Succeed`, `ContainElement`, `Equal`, `MatchError`, and `Eventually` to assert test outcomes. The example covers scenarios like successful checkouts, unavailable books, and placing holds. ```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 Patio Development Dependencies Source: https://github.com/sgl-project/rbg/blob/main/python/patio/README.md Installs additional Python packages required for development and testing of the Patio module. This includes testing frameworks and utilities. ```bash pip install -r requirements-dev.txt ``` -------------------------------- ### Creating a Logger with Context in Go Source: https://github.com/sgl-project/rbg/blob/main/vendor/sigs.k8s.io/controller-runtime/TMP-LOGGING.md Shows how to create a logger with specific context (key-value pairs) within a Go function. This is useful for adding relevant information to logs that pertains to a specific operation or request. ```go func (r *Reconciler) Reconcile(req reconcile.Request) (reconcile.Response, error) { logger := logger.WithValues("pod", req.NamespacedName) // do some stuff logger.Info("starting reconciliation") } ``` -------------------------------- ### Install Patio Dependencies Source: https://github.com/sgl-project/rbg/blob/main/python/patio/README.md Installs the required Python packages for the Patio module using pip and a requirements file. This ensures all necessary libraries are available. ```bash pip install -r requirements.txt ``` -------------------------------- ### Verify kubectl-rbg Installation Source: https://github.com/sgl-project/rbg/blob/main/doc/features/kubectl-rbg.md Confirms that kubectl-rbg has been installed correctly and is available as a kubectl plugin. It checks if the plugin is listed and if the help command functions as expected. ```shell $ kubectl plugin list | grep rbg # Expected output /usr/local/bin/kubectl-rbg $ kubectl rbg -h # The above command works the same as "kubectl-rbg -h" Kubectl plugin for RoleBasedGroup Usage: kubectl [command] Available Commands: completion Generate the autocompletion script for the specified shell help Help about any command rollout Manage the rollout of a rbg object status Display rbg status information Flags: --as string Username to impersonate for the operation. User could be a regular user or a service account in a namespace. --as-group stringArray Group to impersonate for the operation, this flag can be repeated to specify multiple groups. --as-uid string UID to impersonate for the operation. --cache-dir string Default cache directory (default "/Users/gxf/.kube/cache") --certificate-authority string Path to a cert file for the certificate authority --client-certificate string Path to a client certificate file for TLS --client-key string Path to a client key file for TLS --cluster string The name of the kubeconfig cluster to use --context string The name of the kubeconfig context to use --disable-compression If true, opt-out of response compression for all requests to the server -h, --help help for kubectl --insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure --kubeconfig string Path to the kubeconfig file to use for CLI requests. -n, --namespace string If present, the namespace scope for this CLI request --request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0") -s, --server string The address and port of the Kubernetes API server --tls-server-name string Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used --token string Bearer token for authentication to the API server --user string The name of the kubeconfig user to use -v, --v Level number for the log level verbosity --version version for kubectl Use "kubectl [command] --help" for more information about a command. ```