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

wip: disable post-start functions that are done in snc #4560

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
9 changes: 3 additions & 6 deletions pkg/crc/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,10 @@ func EnsureGeneratedClientCAPresentInTheCluster(ctx context.Context, ocConfig oc
}

logging.Info("Updating root CA cert to admin-kubeconfig-client-ca configmap...")
jsonPath := fmt.Sprintf(`'{"data": {"ca-bundle.crt": %q}}'`, selfSignedCAPem)
cmdArgs := []string{"patch", "configmap", "admin-kubeconfig-client-ca",
"-n", "openshift-config", "--patch", jsonPath}
_, stderr, err = ocConfig.RunOcCommand(cmdArgs...)
if err != nil {
return fmt.Errorf("Failed to patch admin-kubeconfig-client-ca config map with new CA` %v: %s", err, stderr)
if err := sshRunner.CopyData(selfSignedCAPem, "/opt/crc/custom-ca.crt", 0644); err != nil {
return fmt.Errorf("Failed to copy generated CA file to VM: %v", err)
}

if err := sshRunner.CopyFile(constants.KubeconfigFilePath, ocConfig.KubeconfigPath, 0644); err != nil {
return fmt.Errorf("Failed to copy generated kubeconfig file to VM: %v", err)
}
Expand Down
33 changes: 4 additions & 29 deletions pkg/crc/cluster/kubeadmin_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

"github.com/crc-org/crc/v2/pkg/crc/constants"
"github.com/crc-org/crc/v2/pkg/crc/logging"
"github.com/crc-org/crc/v2/pkg/crc/oc"
"github.com/crc-org/crc/v2/pkg/crc/ssh"
"golang.org/x/crypto/bcrypt"
)

Expand All @@ -29,7 +29,7 @@
}

// UpdateKubeAdminUserPassword updates the htpasswd secret
func UpdateKubeAdminUserPassword(ctx context.Context, ocConfig oc.Config, newPassword string) error {
func UpdateKubeAdminUserPassword(ctx context.Context, sshRunner *ssh.Runner, newPassword string) error {

Check failure on line 32 in pkg/crc/cluster/kubeadmin_password.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04, 1.22)

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)

Check failure on line 32 in pkg/crc/cluster/kubeadmin_password.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 1.22)

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)

Check failure on line 32 in pkg/crc/cluster/kubeadmin_password.go

View workflow job for this annotation

GitHub Actions / build (macOS-14, 1.22)

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)

Check failure on line 32 in pkg/crc/cluster/kubeadmin_password.go

View workflow job for this annotation

GitHub Actions / build (macOS-13, 1.22)

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)

Check failure on line 32 in pkg/crc/cluster/kubeadmin_password.go

View workflow job for this annotation

GitHub Actions / build (windows-2022, 1.22)

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
if newPassword != "" {
logging.Infof("Overriding password for kubeadmin user")
if err := os.WriteFile(constants.GetKubeAdminPasswordPath(), []byte(strings.TrimSpace(newPassword)), 0600); err != nil {
Expand All @@ -41,39 +41,14 @@
if err != nil {
return fmt.Errorf("Cannot read the kubeadmin user password from file: %w", err)
}
credentials := map[string]string{
"developer": "developer",
"kubeadmin": kubeAdminPassword,
}

if err := WaitForOpenshiftResource(ctx, ocConfig, "secret"); err != nil {
if err := sshRunner.CopyDataPrivileged([]byte(kubeAdminPassword), "/opt/crc/pass_kubeadmin", 0600); err != nil {
return err
}

given, stderr, err := ocConfig.RunOcCommandPrivate("get", "secret", "htpass-secret", "-n", "openshift-config", "-o", `jsonpath="{.data.htpasswd}"`)
if err != nil {
return fmt.Errorf("%s:%v", stderr, err)
}
ok, externals, err := compareHtpasswd(given, credentials)
if err != nil {
if err := sshRunner.CopyDataPrivileged([]byte("developer"), "/opt/crc/pass_developer", 0600); err != nil {
return err
}
if ok {
return nil
}

logging.Infof("Changing the password for the kubeadmin user")
expected, err := getHtpasswd(credentials, externals)
if err != nil {
return err
}
cmdArgs := []string{"patch", "secret", "htpass-secret", "-p",
fmt.Sprintf(`'{"data":{"htpasswd":"%s"}}'`, expected),
"-n", "openshift-config", "--type", "merge"}
_, stderr, err = ocConfig.RunOcCommandPrivate(cmdArgs...)
if err != nil {
return fmt.Errorf("Failed to update kubeadmin password %v: %s", err, stderr)
}
return nil
}

Expand Down
30 changes: 10 additions & 20 deletions pkg/crc/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
return nil
}

func growRootFileSystem(sshRunner *crcssh.Runner, preset crcPreset.Preset, persistentVolumeSize int) error {

Check failure on line 112 in pkg/crc/machine/start.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04, 1.22)

func `growRootFileSystem` is unused (unused)

Check failure on line 112 in pkg/crc/machine/start.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 1.22)

func `growRootFileSystem` is unused (unused)

Check failure on line 112 in pkg/crc/machine/start.go

View workflow job for this annotation

GitHub Actions / build (macOS-14, 1.22)

func `growRootFileSystem` is unused (unused)

Check failure on line 112 in pkg/crc/machine/start.go

View workflow job for this annotation

GitHub Actions / build (macOS-13, 1.22)

func `growRootFileSystem` is unused (unused)

Check failure on line 112 in pkg/crc/machine/start.go

View workflow job for this annotation

GitHub Actions / build (windows-2022, 1.22)

func `growRootFileSystem` is unused (unused)
rootPart, err := getrootPartition(sshRunner, preset)
if err != nil {
return err
Expand Down Expand Up @@ -147,7 +147,7 @@
return nil
}

func getrootPartition(sshRunner *crcssh.Runner, preset crcPreset.Preset) (string, error) {

Check failure on line 150 in pkg/crc/machine/start.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04, 1.22)

func `getrootPartition` is unused (unused)

Check failure on line 150 in pkg/crc/machine/start.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 1.22)

func `getrootPartition` is unused (unused)

Check failure on line 150 in pkg/crc/machine/start.go

View workflow job for this annotation

GitHub Actions / build (macOS-14, 1.22)

func `getrootPartition` is unused (unused)

Check failure on line 150 in pkg/crc/machine/start.go

View workflow job for this annotation

GitHub Actions / build (macOS-13, 1.22)

func `getrootPartition` is unused (unused)

Check failure on line 150 in pkg/crc/machine/start.go

View workflow job for this annotation

GitHub Actions / build (windows-2022, 1.22)

func `getrootPartition` is unused (unused)
diskType := "xfs"
if preset == crcPreset.Microshift {
diskType = "LVM2_member"
Expand All @@ -167,7 +167,7 @@
return rootPart, nil
}

func growLVForMicroshift(sshRunner *crcssh.Runner, lvFullName string, rootPart string, persistentVolumeSize int) error {

Check failure on line 170 in pkg/crc/machine/start.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04, 1.22)

func `growLVForMicroshift` is unused (unused)

Check failure on line 170 in pkg/crc/machine/start.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 1.22)

func `growLVForMicroshift` is unused (unused)

Check failure on line 170 in pkg/crc/machine/start.go

View workflow job for this annotation

GitHub Actions / build (macOS-14, 1.22)

func `growLVForMicroshift` is unused (unused)

Check failure on line 170 in pkg/crc/machine/start.go

View workflow job for this annotation

GitHub Actions / build (macOS-13, 1.22)

func `growLVForMicroshift` is unused (unused)

Check failure on line 170 in pkg/crc/machine/start.go

View workflow job for this annotation

GitHub Actions / build (windows-2022, 1.22)

func `growLVForMicroshift` is unused (unused)
if _, _, err := sshRunner.RunPrivileged("Resizing the physical volume(PV)", "/usr/sbin/pvresize", "--devices", rootPart, rootPart); err != nil {
return err
}
Expand Down Expand Up @@ -427,11 +427,6 @@
return nil, errors.Wrap(err, "Error updating public key")
}

// Trigger disk resize, this will be a no-op if no disk size change is needed
if err := growRootFileSystem(sshRunner, startConfig.Preset, startConfig.PersistentVolumeSize); err != nil {
return nil, errors.Wrap(err, "Error updating filesystem size")
}

// Start network time synchronization if `CRC_DEBUG_ENABLE_STOP_NTP` is not set
if stopNtp, _ := strconv.ParseBool(os.Getenv("CRC_DEBUG_ENABLE_STOP_NTP")); stopNtp {
logging.Info("Stopping network time synchronization in CRC VM")
Expand Down Expand Up @@ -542,6 +537,15 @@
return nil, errors.Wrap(err, "Failed to check certificate validity")
}

// copy the pull secret into /opt/crc/pull-secret in the instance
pullSecret, err := startConfig.PullSecret.Value()
if err != nil {
return nil, err
}
if err := sshRunner.CopyDataPrivileged([]byte(pullSecret), "/opt/crc/pull-secret", 0600); err != nil {
return nil, errors.Wrap(err, "Unable to send pull-secret to instance")
}

logging.Info("Starting kubelet service")
sd := systemd.NewInstanceSystemdCommander(sshRunner)
if err := sd.Start("kubelet"); err != nil {
Expand All @@ -567,10 +571,6 @@
return nil, err
}

if err := cluster.EnsurePullSecretPresentInTheCluster(ctx, ocConfig, startConfig.PullSecret); err != nil {
return nil, errors.Wrap(err, "Failed to update cluster pull secret")
}

if err := cluster.EnsureSSHKeyPresentInTheCluster(ctx, ocConfig, constants.GetPublicKeyPath()); err != nil {
return nil, errors.Wrap(err, "Failed to update ssh public key to machine config")
}
Expand All @@ -579,20 +579,10 @@
return nil, errors.Wrap(err, "Failed to update pull secret on the disk")
}

if err := cluster.UpdateKubeAdminUserPassword(ctx, ocConfig, startConfig.KubeAdminPassword); err != nil {
if err := cluster.UpdateKubeAdminUserPassword(ctx, sshRunner, startConfig.KubeAdminPassword); err != nil {
return nil, errors.Wrap(err, "Failed to update kubeadmin user password")
}

if err := cluster.EnsureClusterIDIsNotEmpty(ctx, ocConfig); err != nil {
return nil, errors.Wrap(err, "Failed to update cluster ID")
}

if client.useVSock() {
if err := ensureRoutesControllerIsRunning(sshRunner, ocConfig); err != nil {
return nil, err
}
}

if client.monitoringEnabled() {
logging.Info("Enabling cluster monitoring operator...")
if err := cluster.StartMonitoring(ocConfig); err != nil {
Expand Down
23 changes: 0 additions & 23 deletions pkg/crc/services/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
"github.com/crc-org/crc/v2/pkg/crc/network"
"github.com/crc-org/crc/v2/pkg/crc/network/httpproxy"
"github.com/crc-org/crc/v2/pkg/crc/services"
"github.com/crc-org/crc/v2/pkg/crc/systemd"
"github.com/crc-org/crc/v2/pkg/crc/systemd/states"
)

const (
Expand All @@ -28,10 +26,6 @@ func init() {
}

func RunPostStart(serviceConfig services.ServicePostStartConfig) error {
if err := setupDnsmasq(serviceConfig); err != nil {
return err
}

if err := runPostStartForOS(serviceConfig); err != nil {
return err
}
Expand All @@ -44,23 +38,6 @@ func RunPostStart(serviceConfig services.ServicePostStartConfig) error {
return network.UpdateResolvFileOnInstance(serviceConfig.SSHRunner, resolvFileValues)
}

func setupDnsmasq(serviceConfig services.ServicePostStartConfig) error {
if serviceConfig.NetworkMode == network.UserNetworkingMode {
return nil
}

if err := createDnsmasqDNSConfig(serviceConfig); err != nil {
return err
}
sd := systemd.NewInstanceSystemdCommander(serviceConfig.SSHRunner)
if state, err := sd.Status(dnsmasqService); err != nil || state != states.Running {
if err := sd.Enable(dnsmasqService); err != nil {
return err
}
}
return sd.Start(dnsmasqService)
}

func getResolvFileValues(serviceConfig services.ServicePostStartConfig) (network.ResolvFileValues, error) {
dnsServers, err := dnsServers(serviceConfig)
if err != nil {
Expand Down
Loading