Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with registries required fields #357

Merged
merged 1 commit into from
Jul 10, 2024
Merged
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
37 changes: 22 additions & 15 deletions pkg/rke2/registries.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const (
DefaultRKE2RegistriesLocation string = "/etc/rancher/rke2/registries.yaml"

registryCertsPath string = "/etc/rancher/rke2/tls"
cacert string = "ca.crt"
tlskey string = "tls.key"
tlscert string = "tls.crt"
)

// GenerateRegistries generates the registries.yaml file and the corresponding
Expand Down Expand Up @@ -69,24 +72,28 @@ func GenerateRegistries(rke2ConfigRegistry RegistryScope) (*Registry, []bootstra
return &Registry{}, []bootstrapv1.File{}, err
}

for _, secretEntry := range []string{"tls.crt", "tls.key", "ca.crt"} {
if tlsSecret.Data[secretEntry] == nil {
rke2ConfigRegistry.Logger.Error(err, "TLS Secret for the registry is missing entries!", "secret-missing-entry", secretEntry)

return &Registry{}, []bootstrapv1.File{}, err
registryConfig.TLS = &TLSConfig{}

for _, secretEntry := range []string{tlscert, tlskey, cacert} {
if tlsSecret.Data[secretEntry] != nil {
files = append(files, bootstrapv1.File{
Path: registryCertsPath + "/" + secretEntry,
Content: string(tlsSecret.Data[secretEntry]),
})

switch secretEntry {
case tlscert:
registryConfig.TLS.CertFile = registryCertsPath + "/" + tlscert
case tlskey:
registryConfig.TLS.KeyFile = registryCertsPath + "/" + tlskey
case cacert:
registryConfig.TLS.CAFile = registryCertsPath + "/" + cacert
}
}

files = append(files, bootstrapv1.File{
Path: registryCertsPath + "/" + secretEntry,
Content: string(tlsSecret.Data[secretEntry]),
})
}

registryConfig.TLS = &TLSConfig{
InsecureSkipVerify: regConfig.TLS.InsecureSkipVerify,
CAFile: registryCertsPath + "/" + "ca.crt",
CertFile: registryCertsPath + "/" + "tls.crt",
KeyFile: registryCertsPath + "/" + "tls.key",
if regConfig.TLS.InsecureSkipVerify {
registryConfig.TLS.InsecureSkipVerify = regConfig.TLS.InsecureSkipVerify
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/rke2/registries_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ type AuthConfig struct {

// TLSConfig contains the CA/Cert/Key used for a registry.
type TLSConfig struct {
CAFile string `json:"ca_file" toml:"ca_file" yaml:"ca_file"`
CertFile string `json:"cert_file" toml:"cert_file" yaml:"cert_file"`
KeyFile string `json:"key_file" toml:"key_file" yaml:"key_file"`
InsecureSkipVerify bool `json:"insecure_skip_verify" toml:"insecure_skip_verify" yaml:"insecure_skip_verify"`
CAFile string `json:"ca_file,omitempty" toml:"ca_file" yaml:"ca_file,omitempty"`
CertFile string `json:"cert_file,omitempty" toml:"cert_file" yaml:"cert_file,omitempty"`
KeyFile string `json:"key_file,omitempty" toml:"key_file" yaml:"key_file,omitempty"`
InsecureSkipVerify bool `json:"insecure_skip_verify,omitempty" toml:"insecure_skip_verify" yaml:"insecure_skip_verify,omitempty"`
}

// Registry is registry settings including mirrors, TLS, and credentials.
Expand Down
Loading