Skip to content

Commit

Permalink
feat: automatically append talos.config to the Environment
Browse files Browse the repository at this point in the history
Fixes #460

With this change, it's no longer necessary to supply `talos.config` in
the Environment - it is appended dynamically during the boot process.

So `talos.config` is removed even from the default Environment, as this
makes it update automatically if Sidero endpoint gets changed.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
  • Loading branch information
smira committed Nov 18, 2021
1 parent 0e7f8a6 commit acb5f57
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func EnvironmentDefaultSpec(talosRelease, apiEndpoint string, apiPort uint16) *E
args = append(args, kernel.DefaultArgs...)
args = append(args, "console=tty0", "console=ttyS0", "earlyprintk=ttyS0")
args = append(args, "initrd=initramfs.xz", "talos.platform=metal")
args = append(args, fmt.Sprintf("talos.config=http://%s:%d/configdata?uuid=", apiEndpoint, apiPort))
sort.Strings(args)

return &EnvironmentSpec{
Expand Down
37 changes: 32 additions & 5 deletions app/sidero-controller-manager/internal/ipxe/ipxe_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/talos-systems/go-procfs/procfs"
talosconstants "github.com/talos-systems/talos/pkg/machinery/constants"

infrav1 "github.com/talos-systems/sidero/app/caps-controller-manager/api/v1alpha3"
metalv1alpha1 "github.com/talos-systems/sidero/app/sidero-controller-manager/api/v1alpha1"
Expand Down Expand Up @@ -364,6 +365,8 @@ func newDefaultEnvironment() (env *metalv1alpha1.Environment, err error) {
return nil, err
}

appendTalosConfigArgument(env)

return env, nil
}

Expand All @@ -374,6 +377,8 @@ func newEnvironmentFromServer(server *metalv1alpha1.Server) (env *metalv1alpha1.
return nil, err
}

appendTalosConfigArgument(env)

return env, nil
}

Expand All @@ -384,17 +389,39 @@ func newEnvironmentFromServerClass(serverBinding *infrav1.ServerBinding) (env *m
return nil, err
}

if serverClassResource.Spec.EnvironmentRef != nil {
env = &metalv1alpha1.Environment{}
if serverClassResource.Spec.EnvironmentRef == nil {
return env, nil
}

if err := c.Get(context.Background(), types.NamespacedName{Namespace: "", Name: serverClassResource.Spec.EnvironmentRef.Name}, env); err != nil {
return nil, err
}
env = &metalv1alpha1.Environment{}

if err := c.Get(context.Background(), types.NamespacedName{Namespace: "", Name: serverClassResource.Spec.EnvironmentRef.Name}, env); err != nil {
return nil, err
}

appendTalosConfigArgument(env)

return env, nil
}

func appendTalosConfigArgument(env *metalv1alpha1.Environment) {
args := env.Spec.Kernel.Args

talosConfigPrefix := talosconstants.KernelParamConfig + "="

for _, arg := range args {
if strings.HasPrefix(arg, talosConfigPrefix) {
// Environment already has talos.config
return
}
}

// patch environment with the link to the metadata server
env.Spec.Kernel.Args = append(env.Spec.Kernel.Args,
fmt.Sprintf("%s=http://%s:%d/configdata?uuid=", talosconstants.KernelParamConfig, apiEndpoint, apiPort),
)
}

func markAsPXEBooted(server *metalv1alpha1.Server) error {
patchHelper, err := patch.NewHelper(server, c)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions sfyra/pkg/tests/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package tests

import (
"context"
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -91,7 +90,6 @@ func TestEnvironmentCreate(ctx context.Context, metalClient client.Client, clust
cmdline.Append("panic", "1")
cmdline.Append("talos.platform", "metal")
cmdline.Append("talos.shutdown", "halt")
cmdline.Append("talos.config", fmt.Sprintf("http://%s:8081/configdata?uuid=", cluster.SideroComponentsIP()))
cmdline.Append("initrd", "initramfs.xz")

environment.APIVersion = constants.SideroAPIVersion
Expand Down
12 changes: 10 additions & 2 deletions website/content/docs/v0.5/Guides/first-cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ kubectl patch deploy -n sidero-system sidero-controller-manager --type='json' -p

#### Update Environment

The metadata server's information needs to be updated in the default environment.
Edit the environment with `kubectl edit environment default` and update the `talos.config` kernel arg with the IP of one of the management plane nodes (or the DNS entry you created).
The metadata server's information might need to be updated in the default environment.

<!-- textlint-disable -->

Sidero by default appends `talos.config` kernel argument with based on the flags `--api-endpoint` and `--api-port` to the `sidero-controller-manager`:
`talos.config=http://$API_ENDPOINT:$API_PORT/configdata?uuid=`.

<!-- textlint-enable -->

If this default value doesn't apply, edit the environment with `kubectl edit environment default` and add the `talos.config` kernel arg with the IP of one of the management plane nodes (or the DNS entry you created).

### Update DHCP

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ spec:
- pti=on
- random.trust_cpu=on
- slab_nomerge=
- talos.config=http://$PUBLIC_IP:8081/configdata?uuid=
- talos.platform=metal
initrd:
url: "https://github.com/talos-systems/talos/releases/download/v0.13.0/initramfs-amd64.xz"
Expand Down

0 comments on commit acb5f57

Please sign in to comment.