### Install dataurl Package Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/vincent-petithory/dataurl/README.md Use go get to install the dataurl package. ```go go get github.com/vincent-petithory/dataurl ``` -------------------------------- ### Install IAM Go Client Source: https://github.com/coreos/ignition/blob/main/vendor/cloud.google.com/go/iam/README.md Use 'go get' to install the IAM Go client library. This command fetches and installs the package and its dependencies. ```bash go get cloud.google.com/go/iam ``` -------------------------------- ### Install and Run Local Go Doc Site Source: https://github.com/coreos/ignition/blob/main/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Installs and runs a local Go Doc site using pkgsite. Ensure you have Go installed and configured. ```sh go install golang.org/x/pkgsite/cmd/pkgsite@latest pkgsite ``` -------------------------------- ### Install copystructure Go Library Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/mitchellh/copystructure/README.md Use `go get` to install the copystructure library. This is the standard method for obtaining Go packages. ```bash $ go get github.com/mitchellh/copystructure ``` -------------------------------- ### Install Azure Blob Storage SDK for Go Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/README.md Install the Azure Blob Storage client module for Go using go get. ```bash go get github.com/Azure/azure-sdk-for-go/sdk/storage/azblob ``` -------------------------------- ### Install UUID Package Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/google/uuid/README.md Use this command to install the UUID package using go get. ```sh go get github.com/google/uuid ``` -------------------------------- ### Install godbus/dbus Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/godbus/dbus/v5/README.md Install the dbus library using the go get command. Requires Go 1.12 or later. ```bash go get github.com/godbus/dbus/v5 ``` -------------------------------- ### Create Azure Storage Account using Azure CLI Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/README.md Example of creating an Azure storage account using the Azure CLI. Ensure you have the Azure CLI installed and configured. ```bash az storage account create --name MyStorageAccount --resource-group MyResourceGroup --location westus --sku Standard_LRS ``` -------------------------------- ### Install Google Auth Library for Go Source: https://github.com/coreos/ignition/blob/main/vendor/cloud.google.com/go/auth/README.md Use this command to install the latest version of the Google Auth library for Go. ```bash go get cloud.google.com/go/auth@latest ``` -------------------------------- ### Install Azure Identity SDK for Go Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/README.md If you plan to authenticate with Azure Active Directory, install the azidentity module as well. ```bash go get github.com/Azure/azure-sdk-for-go/sdk/azidentity ``` -------------------------------- ### Install Compute Metadata Library Source: https://github.com/coreos/ignition/blob/main/vendor/cloud.google.com/go/compute/metadata/README.md Use this command to install the compute metadata library for your Go project. ```bash go get cloud.google.com/go/compute/metadata ``` -------------------------------- ### Install the Azure Identity Module Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/README.md Installs the Azure Identity module using Go modules. ```sh go get -u github.com/Azure/azure-sdk-for-go/sdk/azidentity ``` -------------------------------- ### Application Setup with logr Logger Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/go-logr/logr/README.md Demonstrates how to initialize a logr.Logger with a specific implementation early in an application's lifecycle. This logger can then be passed to other parts of the application. ```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 ... } ``` -------------------------------- ### Enable and Start a Systemd Service Source: https://github.com/coreos/ignition/blob/main/docs/examples.md Write a new systemd service unit that is enabled and starts on boot as a dependency of multi-user.target. ```json { "ignition": { "version": "3.0.0" }, "systemd": { "units": [{ "name": "example.service", "enabled": true, "contents": "[Service]\nType=oneshot\nExecStart=/usr/bin/echo Hello World\n\n[Install]\nWantedBy=multi-user.target" }] } } ``` ```ini [Service] Type=oneshot ExecStart=/usr/bin/echo Hello World [Install] WantedBy=multi-user.target ``` -------------------------------- ### Start TFTP Server Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/pin/tftp/README.md Initializes and starts a new TFTP server with specified read and write handlers. The server listens on UDP port 69 and blocks until Shutdown is called. An optional timeout can be set. ```go func main() { // use nil in place of handler to disable read or write operations s := tftp.NewServer(readHandler, writeHandler) s.SetTimeout(5 * time.Second) // optional err := s.ListenAndServe(":69") // blocks until s.Shutdown() is called if err != nil { fmt.Fprintf(os.Stdout, "server: %v\n", err) os.Exit(1) } } ``` -------------------------------- ### Install blkid Headers Source: https://github.com/coreos/ignition/blob/main/docs/development.md Install the blkid development headers required for Ignition. Choose the command appropriate for your Linux distribution. ```sh # Debian/Ubuntu sudo apt-get install libblkid-dev # RPM-based sudo dnf install libblkid-devel ``` -------------------------------- ### Install gRPC-Go Source: https://github.com/coreos/ignition/blob/main/vendor/google.golang.org/grpc/README.md Add this import statement to your Go code to automatically fetch gRPC-Go dependencies during build, run, or test. ```go import "google.golang.org/grpc" ``` -------------------------------- ### Set Kernel Arguments Source: https://github.com/coreos/ignition/blob/main/docs/examples.md Configures kernel arguments, ensuring 'example' and 'foo bar' exist while 'somekarg' is removed. This is useful for system boot-time configurations. ```json { "ignition": {"version": "3.3.0"}, "kernelArguments": { "shouldExist": ["example", "foo bar"], "shouldNotExist": ["somekarg"] } } ``` -------------------------------- ### Configure Go Client Code Generation Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/aws/smithy-go/README.md Example smithy-build.json configuration for the `go-codegen` plugin. Specifies the service, module, and Go directive for client generation. ```json { "version": "1.0", "sources": [ "models" ], "maven": { "dependencies": [ "software.amazon.smithy.go:smithy-go-codegen:0.1.0" ] }, "plugins": { "go-codegen": { "service": "example.weather#Weather", "module": "github.com/example/weather", "generateGoMod": true, "goDirective": "1.24" } } } ``` -------------------------------- ### Define Exporter Interface Source: https://github.com/coreos/ignition/blob/main/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Example of defining a basic Exporter interface. ```go type Exporter interface { Export() } ``` -------------------------------- ### Commit Convention Example Source: https://github.com/coreos/ignition/blob/main/AGENTS.md Illustrates the expected format for commit messages in the Ignition project, emphasizing a subsystem prefix, lowercase description, and imperative mood. ```git providers/hetzner: add Hetzner Cloud support ``` ```git config/v3_6: stabilize spec ``` ```git internal/exec/stages/files: fix permission handling ``` ```git docs: update supported platforms ``` ```git *: refactor provider interface ``` ```git tests: add filesystem blackbox tests ``` -------------------------------- ### Initialize Observability Explicitly Source: https://github.com/coreos/ignition/blob/main/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Encapsulate observability setup in constructor functions for clear ownership and scope, ensuring it's explicit and side-effect free. ```go import ( "errors" semconv "go.opentelemetry.io/otel/semconv/v1.40.0" "go.opentelemetry.io/otel/semconv/v1.40.0/otelconv" ) type SDKComponent struct { inst *instrumentation } func NewSDKComponent(config Config) (*SDKComponent, error) { inst, err := newInstrumentation() if err != nil { return nil, err } return &SDKComponent{inst: inst}, nil } type instrumentation struct { inflight otelconv.SDKComponentInflight exported otelconv.SDKComponentExported } func newInstrumentation() (*instrumentation, error) { if !x.Observability.Enabled() { return nil, nil } meter := otel.GetMeterProvider().Meter( "", metric.WithInstrumentationVersion(sdk.Version()), metric.WithSchemaURL(semconv.SchemaURL), ) inst := &instrumentation{} var err, e error inst.inflight, e = otelconv.NewSDKComponentInflight(meter) err = errors.Join(err, e) inst.exported, e = otelconv.NewSDKComponentExported(meter) err = errors.Join(err, e) return inst, err } ``` ```go // ❌ Avoid this pattern. func (c *Component) initObservability() { // Initialize observability metrics if !x.Observability.Enabled() { return } // Initialize observability metrics c.inst = &instrumentation{/* ... */} } ``` -------------------------------- ### Managed identity authentication with autorest/adal Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/MIGRATION.md This example shows how to authenticate using a managed identity with the autorest/adal package by creating a service principal token from a managed identity. ```go import ( "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-06-01/subscriptions" "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/adal" ) spt, err := adal.NewServicePrincipalTokenFromManagedIdentity("https://management.azure.com/", nil) handle(err) client := subscriptions.NewClient() client.Authorizer = autorest.NewBearerAuthorizer(spt) ``` -------------------------------- ### Create a Cloud Storage Client Source: https://github.com/coreos/ignition/blob/main/vendor/cloud.google.com/go/storage/README.md Initialize a storage.Client to be used for all subsequent operations. Handle potential errors during client creation. ```go client, err := storage.NewClient(ctx) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Create New Configuration Instance Source: https://github.com/coreos/ignition/blob/main/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Creates a new configuration instance by applying a variadic list of options to a default config struct. This function is usually 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 } ``` -------------------------------- ### Create and Indent XML Document Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/beevik/etree/README.md Creates a new XML document from scratch, adds processing instructions and elements, indents it, and writes it to standard output. Ensure the 'os' package is imported for os.Stdout. ```go doc := etree.NewDocument() doc.CreateProcInst("xml", `version="1.0" encoding="UTF-8"`) doc.CreateProcInst("xml-stylesheet", `type="text/xsl" href="style.xsl"`) people := doc.CreateElement("People") people.CreateComment("These are all known people") jon := people.CreateElement("Person") jon.CreateAttr("name", "Jon") sally := people.CreateElement("Person") sally.CreateAttr("name", "Sally") doc.Indent(2) doc.WriteTo(os.Stdout) ``` -------------------------------- ### Get OpenTelemetry Go Package Source: https://github.com/coreos/ignition/blob/main/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Use `go get` to download the opentelemetry-go package. This command may produce warnings that can be ignored. ```go go get -d go.opentelemetry.io/otel ``` -------------------------------- ### Install Schematyper for Go Struct Generation Source: https://github.com/coreos/ignition/blob/main/docs/development.md Install the schematyper tool to generate Go structs from JSON schema definitions. This is a prerequisite for modifying the Ignition config spec. ```sh go get -u github.com/idubinskiy/schematyper ``` -------------------------------- ### Update Dependencies using go get and go mod tidy Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/golang-jwt/jwt/v5/MIGRATION_GUIDE.md After changing the import path, update your project's dependencies using 'go get' and 'go mod tidy' to incorporate the new library version. ```bash go get github.com/golang-jwt/jwt/v4 go mod tidy ``` -------------------------------- ### Client certificate authentication with autorest/adal Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/MIGRATION.md This example shows how to authenticate using a client certificate with the autorest/adal package. It reads the certificate, decodes it, and then creates a service principal token. ```go import ( "os" "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-06-01/subscriptions" "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/adal" ) certData, err := os.ReadFile("./example.pfx") handle(err) certificate, rsaPrivateKey, err := decodePkcs12(certData, "") handle(err) oauthCfg, err := adal.NewOAuthConfig("https://login.microsoftonline.com", tenantID) handle(err) spt, err := adal.NewServicePrincipalTokenFromCertificate( *oauthConfig, clientID, certificate, rsaPrivateKey, "https://management.azure.com/", ) client := subscriptions.NewClient() client.Authorizer = autorest.NewBearerAuthorizer(spt) ``` -------------------------------- ### Import Golang JWT Package Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/golang-jwt/jwt/v5/README.md Import the jwt package into your Go code after installation. ```go import "github.com/golang-jwt/jwt/v5" ``` -------------------------------- ### Install Golang JWT Package Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/golang-jwt/jwt/v5/README.md Use this command to add the jwt-go package as a dependency in your Go program. ```sh go get -u github.com/golang-jwt/jwt/v5 ``` -------------------------------- ### Client certificate authentication with azidentity Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/Azure/azure-sdk-for-go/sdk/azidentity/MIGRATION.md This snippet demonstrates authenticating using a client certificate with the azidentity package. It parses the certificate data and then creates a new subscriptions client. ```go import ( "os" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions" ) certData, err := os.ReadFile("./example.pfx") handle(err) certs, key, err := azidentity.ParseCertificates(certData, nil) handle(err) cred, err = azidentity.NewClientCertificateCredential(tenantID, clientID, certs, key, nil) handle(err) client, err := armsubscriptions.NewClient(cred, nil) handle(err) ``` -------------------------------- ### Run All Blackbox Tests Source: https://github.com/coreos/ignition/blob/main/docs/development.md Execute all blackbox tests. Ensure you have the necessary host system dependencies installed. ```sh ./build_blackbox_tests sudo sh -c 'PATH=$PWD/bin/amd64:$PATH ./tests.test' ``` -------------------------------- ### Configure HTTP Pipeline Options Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/migrationguide.md Configure HTTP pipeline options by passing an azcore.ClientOptions struct to the azblob.ClientOptions when creating a new client. ```go client, err := azblob.NewClient(account, cred, &azblob.ClientOptions{ ClientOptions: azcore.ClientOptions{ // configure HTTP pipeline options here }, }) ``` -------------------------------- ### Find books by price using compiled path Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/beevik/etree/README.md Finds all books with a price of 49.99 and outputs their titles. This example demonstrates using a pre-compiled path for efficiency when the same path is used multiple times. ```go path := etree.MustCompilePath("./bookstore/book[p:price='49.99']/title") for _, e := range doc.FindElementsPathSeq(path) { fmt.Println(e.Text()) } ``` -------------------------------- ### Deprecate a Flag Source: https://github.com/coreos/ignition/blob/main/vendor/github.com/spf13/pflag/README.md Shows how to mark a flag as deprecated, providing a message to guide users to the recommended alternative. ```go // deprecate a flag by specifying its name and a usage message flags.MarkDeprecated("badflag", "please use --good-flag instead") ``` ```go // deprecate a flag shorthand by specifying its flag name and a usage message flags.MarkShorthandDeprecated("noshorthandflag", "please use --noshorthandflag only") ``` -------------------------------- ### Define Additional Closer Interface Source: https://github.com/coreos/ignition/blob/main/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Example of defining a new interface to add functionality (Close) to an existing type. ```go type Closer interface { Close() } ``` -------------------------------- ### Deterministic Testing Setup in Go Source: https://github.com/coreos/ignition/blob/main/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Isolate the meter provider and use t.Setenv for environment variables to ensure deterministic testing. Reset global state like component ID counters. ```go func TestObservability(t *testing.T) { // Restore state after test to ensure this does not affect other tests. prev := otel.GetMeterProvider() t.Cleanup(func() { otel.SetMeterProvider(prev) }) // Isolate the meter provider for deterministic testing reader := metric.NewManualReader() meterProvider := metric.NewMeterProvider(metric.WithReader(reader)) otel.SetMeterProvider(meterProvider) // Use t.Setenv to ensure environment variable is restored after test. t.Setenv("OTEL_GO_X_OBSERVABILITY", "true") // Reset component ID counter to ensure deterministic component names. componentIDCounter.Store(0) /* ... test code ... */ } ``` -------------------------------- ### Define Super-set Interface Type Source: https://github.com/coreos/ignition/blob/main/vendor/go.opentelemetry.io/otel/CONTRIBUTING.md Example of creating a new type that embeds an existing interface and adds new methods. ```go type ClosingExporter struct { Exporter Close() } ``` -------------------------------- ### Get GPG Key ID Source: https://github.com/coreos/ignition/blob/main/vendor/go.opentelemetry.io/otel/RELEASING.md Retrieve your GPG key ID, which is required for signing release artifacts. The ID is a 16-character string. ```terminal gpg --list-secret-keys --keyid-format=long ```