Skip to content

Commit

Permalink
Merge pull request openshift#3828 from stbenjam/revert-3811-sshKeys
Browse files Browse the repository at this point in the history
Revert " add Passwd to bootstrap served ignition"
  • Loading branch information
openshift-merge-robot authored Jul 29, 2023
2 parents 7df71a1 + 5de8b6e commit 8e61b30
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 120 deletions.
6 changes: 1 addition & 5 deletions pkg/controller/common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,9 @@ func ConvertRawExtIgnitionToV3_1(inRawExtIgn *runtime.RawExtension) (runtime.Raw
return outRawExt, nil
}

func ConvertV3ToV2Ignition(cfg ign3types.Config) (ign2types.Config, error) {
return convertIgnition3to2(cfg)
}

// ConvertRawExtIgnitionToV2 ensures that the Ignition config in
// the RawExtension is spec v2.2, or translates to it.
func ConvertRawExtIgnitionToV2Raw(inRawExtIgn *runtime.RawExtension) (runtime.RawExtension, error) {
func ConvertRawExtIgnitionToV2(inRawExtIgn *runtime.RawExtension) (runtime.RawExtension, error) {
ignCfg, rpt, err := ign3.Parse(inRawExtIgn.Raw)
if err != nil || rpt.IsFatal() {
return runtime.RawExtension{}, fmt.Errorf("parsing Ignition config spec v3.2 failed with error: %w\nReport: %v", err, rpt)
Expand Down
4 changes: 0 additions & 4 deletions pkg/daemon/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -1569,10 +1569,6 @@ func (dn *Daemon) useNewSSHKeyPath() bool {
func (dn *Daemon) updateSSHKeys(newUsers, oldUsers []ign3types.PasswdUser) error {
klog.Info("updating SSH keys")

for _, u := range newUsers {
klog.Infof("Provided User: %s with %d keys", u.Name, len(u.SSHAuthorizedKeys))
}

// Checking to see if absent users need to be deconfigured
deconfigureAbsentUsers(newUsers, oldUsers)

Expand Down
2 changes: 1 addition & 1 deletion pkg/server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (sh *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
serveConf = &converted31
} else {
// Can only be 2.2 here
converted2, err := ctrlcommon.ConvertRawExtIgnitionToV2Raw(conf)
converted2, err := ctrlcommon.ConvertRawExtIgnitionToV2(conf)
if err != nil {
w.Header().Set("Content-Length", "0")
w.WriteHeader(http.StatusInternalServerError)
Expand Down
6 changes: 0 additions & 6 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,15 @@ func appendEncapsulated(conf *igntypes.Config, mc *mcfgv1.MachineConfig, version
// requires an empty Ignition version.
if version == nil || version.Slice()[0] == 3 {
tmpIgnCfg := ctrlcommon.NewIgnConfig()
tmpIgnCfg.Passwd = conf.Passwd
rawTmpIgnCfg, err = json.Marshal(tmpIgnCfg)
if err != nil {
return fmt.Errorf("error marshalling Ignition config: %w", err)
}
} else {
v2, err := ctrlcommon.ConvertV3ToV2Ignition(*conf)
if err != nil {
return err
}
tmpIgnCfg := ign2types.Config{
Ignition: ign2types.Ignition{
Version: ign2types.MaxVersion.String(),
},
Passwd: v2.Passwd,
}
rawTmpIgnCfg, err = json.Marshal(tmpIgnCfg)
if err != nil {
Expand Down
104 changes: 0 additions & 104 deletions test/e2e/mcd_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package e2e_test

import (
"bytes"
"context"
"fmt"
"os/exec"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -1009,108 +1007,6 @@ func TestMCDRotatesCertsOnPausedPool(t *testing.T) {

}

func TestFirstBootHasSSHKeys(t *testing.T) {
cs := framework.NewClientSet("")
outNodeYoungest := bytes.NewBuffer([]byte{})
outErr := bytes.NewBuffer([]byte{})
// get nodes by newest
cmdCombined := "oc get nodes --sort-by .metadata.creationTimestamp | tail -n 1"
cmd := exec.Command("bash", "-c", cmdCombined)
cmd.Stdout = outNodeYoungest
cmd.Stderr = outErr
err := cmd.Run()
require.Nil(t, err, fmt.Sprintf("Got stdout: %s and stderr: %s", outNodeYoungest.String(), outErr))
// get top machineset
cmdCombined = "oc -n openshift-machine-api -o name get machinesets | head -n 1"
cmd = exec.Command("bash", "-c", cmdCombined)
outMSet := bytes.NewBuffer([]byte{})
outErr = bytes.NewBuffer([]byte{})
cmd.Stdout = outMSet
cmd.Stderr = outErr
err = cmd.Run()
require.Nil(t, err, fmt.Sprintf("Got stdout: %s and stderr: %s", outMSet.String(), outErr))
mset := strings.Trim(strings.Split(outMSet.String(), "/")[1], "\n")
// scale a 2nd machine
cmdCombined = "oc scale --replicas=2 machineset " + mset + " -n openshift-machine-api"
cmd = exec.Command("bash", "-c", cmdCombined)
outScale := bytes.NewBuffer([]byte{})
outErr = bytes.NewBuffer([]byte{})
cmd.Stdout = outMSet
cmd.Stderr = outErr
err = cmd.Run()
require.Nil(t, err, fmt.Sprintf("Got stdout: %s and stderr: %s", outScale.String(), outErr))
outNodeYoungestNew := &bytes.Buffer{}
nodeStr := strings.Split(outNodeYoungest.String(), " ")[0]
t.Cleanup(func() {
if len(outNodeYoungestNew.String()) > 0 && strings.Split(outNodeYoungestNew.String(), " ")[0] != nodeStr {
// scale down
cmdCombined = "oc scale --replicas=1 machineset " + mset + " -n openshift-machine-api"
cmd = exec.Command("bash", "-c", cmdCombined)
outScale := bytes.NewBuffer([]byte{})
outErr = bytes.NewBuffer([]byte{})
cmd.Stdout = outMSet
cmd.Stderr = outErr
err = cmd.Run()
splitNodes := []string{}
require.Nil(t, err, fmt.Sprintf("Got stdout: %s and stderr: %s", outScale.String(), outErr))
if err := wait.PollUntilContextTimeout(context.TODO(), 2*time.Second, 20*time.Minute, false, func(ctx context.Context) (bool, error) {
outNodeYoungestNew = bytes.NewBuffer([]byte{})
outErr = bytes.NewBuffer([]byte{})
// get all nodes
cmdCombined = "oc get nodes"
cmd := exec.Command("bash", "-c", cmdCombined)
cmd.Stdout = outNodeYoungestNew
cmd.Stderr = outErr
err := cmd.Run()
require.Nil(t, err, fmt.Sprintf("Got stdout: %s and stderr: %s", outNodeYoungestNew.String(), outErr))
splitNodes = strings.Split(outNodeYoungestNew.String(), "\n")
for _, n := range splitNodes {
// find the one with scheduling disabled and delete it
if strings.Contains(n, "SchedulingDisabled") {
return false, nil
}
}
return true, nil
}); err != nil {
t.Fatalf("did not get old node upon cleanup: %s", splitNodes)
}
}

})
nodeSplit := []string{"", ""}
if err := wait.PollUntilContextTimeout(context.TODO(), 2*time.Second, 20*time.Minute, false, func(ctx context.Context) (bool, error) {
outNodeYoungestNew = bytes.NewBuffer([]byte{})
outErr = bytes.NewBuffer([]byte{})
// get nodes over and over
cmdCombined = "oc get nodes --sort-by .metadata.creationTimestamp | tail -n 1"
cmd := exec.Command("bash", "-c", cmdCombined)
cmd.Stdout = outNodeYoungestNew
cmd.Stderr = outErr
err := cmd.Run()
require.Nil(t, err, fmt.Sprintf("Got stdout: %s and stderr: %s", outNodeYoungestNew.String(), outErr))
nodeSplit = strings.SplitN(outNodeYoungestNew.String(), " ", 2)
// if node name != first node name and it is ready, we have a node
if nodeSplit[0] != nodeStr && strings.Contains(nodeSplit[1], "Ready") && !strings.Contains(nodeSplit[1], "NotReady") {
return true, nil
}
return false, nil
}); err != nil {
t.Fatal("did not get new node")
}

nodes, err := helpers.GetNodesByRole(cs, "worker")
require.Nil(t, err)
foundNode := false
for _, node := range nodes {
if node.Name == nodeSplit[0] && strings.Contains(nodeSplit[1], "Ready") && !strings.Contains(nodeSplit[1], "NotReady") {
foundNode = true
out := helpers.ExecCmdOnNode(t, cs, node, "cat", "/rootfs/home/core/.ssh/authorized_keys.d/ignition")
t.Logf("Got ssh key file data: %s", out)
require.NotEmpty(t, out)
}
}
require.True(t, foundNode)
}
func createMCToAddFileForRole(name, role, filename, data string) *mcfgv1.MachineConfig {
mcadd := helpers.CreateMC(fmt.Sprintf("%s-%s", name, uuid.NewUUID()), role)

Expand Down

0 comments on commit 8e61b30

Please sign in to comment.