Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ type MetalConfig struct {
NTPServers []string `json:"ntp_servers,omitempty"`
Partition string `json:"partition"`
// Logging contains logging configurations passed to metal-hammer
Logging *Logging `json:"logging,omitempty"`
Logging *Logging `json:"logging,omitempty"`
OciConfigs map[string]*OciCredentials `json:"oci_config,omitempty"`
}

type Logging struct {
Expand Down Expand Up @@ -45,6 +46,13 @@ type CertificateAuth struct {
InsecureSkipVerify bool `json:"insecure_skip_verify,omitempty"`
}

type OciCredentials struct {
// Username that is capable of logging in to the registry
Username string `json:"username,omitempty" yaml:"username,omitempty"`
// Password for the user
Password string `json:"password,omitempty" yaml:"password,omitempty"`
}

// LogType defines which logging backend should be used
type LogType string

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/metal-stack/pixie
go 1.25

require (
github.com/goccy/go-yaml v1.19.2
github.com/metal-stack/metal-api v0.42.4
github.com/metal-stack/v v1.0.3
github.com/pin/tftp/v3 v3.1.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM=
github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
Expand Down
39 changes: 39 additions & 0 deletions pixiecore/cli/grpccmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os"
"strings"

yaml "github.com/goccy/go-yaml"
"github.com/metal-stack/pixie/api"
"github.com/metal-stack/pixie/pixiecore"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -85,6 +86,9 @@ func init() {
grpcCmd.Flags().String("metal-hammer-logging-key", "", "set metal-hammer to send logs to a remote endpoint and authenticate with this key")
grpcCmd.Flags().Bool("metal-hammer-logging-tls-insecure", false, "set metal-hammer to send logs to a remote endpoint without verifying the tls certificate")
grpcCmd.Flags().String("metal-hammer-logging-type", "loki", "set metal-hammer to send logs to a remote endpoint with this logging type")

// metal-hammer oci configs
grpcCmd.Flags().StringSlice("metal-hammer-oci-configs", nil, "multiple metal-hammer oci configs. comma-separated key-value pairs (registry_url=...,username=...,password=...). registry URL is mandatory, login credentials are optional depending on whether the oci image is public.")
}

func getMetalAPIConfig(cmd *cobra.Command) (*api.MetalConfig, error) {
Expand Down Expand Up @@ -219,6 +223,40 @@ func getMetalAPIConfig(cmd *cobra.Command) (*api.MetalConfig, error) {
}
}

metalHammerOciConfigFilePath, err := cmd.Flags().GetString("metal-hammer-oci-config-file-path")
if err != nil {
return nil, fmt.Errorf("error reading flag: %w", err)
}

ociConfigs := make(map[string]*api.OciCredentials)
if metalHammerOciConfigFilePath != "" {
metalHammerOciConfigFileContent, err := os.ReadFile(metalHammerOciConfigFilePath)
if err != nil {
return nil, fmt.Errorf("error retrieving oci configs file: %w", err)
}

type MetalHammerOciConfig struct {
RegistryURL string `yaml:"registry-url"`
Credentials *api.OciCredentials
}
type MetalHammerOciConfigs struct {
OciConfigs []MetalHammerOciConfig `yaml:"oci-configs"`
}
var metalHammerOciConfigs MetalHammerOciConfigs
err = yaml.Unmarshal(metalHammerOciConfigFileContent, &metalHammerOciConfigs)
if err != nil {
return nil, fmt.Errorf("error parsing oci configs: %w", err)
}

for _, config := range metalHammerOciConfigs.OciConfigs {
if config.RegistryURL == "" {
return nil, fmt.Errorf("no registry url specified for oci config: %+v", config)
}

ociConfigs[config.RegistryURL] = config.Credentials
}
}

return &api.MetalConfig{
Debug: metalHammerDebug,
GRPCAddress: grpcAddress,
Expand All @@ -231,5 +269,6 @@ func getMetalAPIConfig(cmd *cobra.Command) (*api.MetalConfig, error) {
NTPServers: ntpServers,
Logging: logging,
Partition: partition,
OciConfigs: ociConfigs,
}, nil
}