diff --git a/pkg/crc/cluster/cluster.go b/pkg/crc/cluster/cluster.go index e07c6a19e6..3fba74ab9f 100644 --- a/pkg/crc/cluster/cluster.go +++ b/pkg/crc/cluster/cluster.go @@ -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) } diff --git a/pkg/crc/cluster/kubeadmin_password.go b/pkg/crc/cluster/kubeadmin_password.go index f8beb9fb13..1fcf5f79ba 100644 --- a/pkg/crc/cluster/kubeadmin_password.go +++ b/pkg/crc/cluster/kubeadmin_password.go @@ -13,7 +13,7 @@ import ( "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" ) @@ -29,7 +29,7 @@ func GenerateKubeAdminUserPassword() error { } // 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 { if newPassword != "" { logging.Infof("Overriding password for kubeadmin user") if err := os.WriteFile(constants.GetKubeAdminPasswordPath(), []byte(strings.TrimSpace(newPassword)), 0600); err != nil { @@ -41,39 +41,14 @@ func UpdateKubeAdminUserPassword(ctx context.Context, ocConfig oc.Config, newPas 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 } diff --git a/pkg/crc/machine/start.go b/pkg/crc/machine/start.go index 17eacb2c33..336f4c0f97 100644 --- a/pkg/crc/machine/start.go +++ b/pkg/crc/machine/start.go @@ -427,11 +427,6 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig) 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") @@ -542,6 +537,15 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig) 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 { @@ -567,10 +571,6 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig) 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") } @@ -579,20 +579,10 @@ func (client *client) Start(ctx context.Context, startConfig types.StartConfig) 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 { diff --git a/pkg/crc/services/dns/dns.go b/pkg/crc/services/dns/dns.go index 91c80db06b..c4f4dc4263 100644 --- a/pkg/crc/services/dns/dns.go +++ b/pkg/crc/services/dns/dns.go @@ -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 ( @@ -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 } @@ -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 {