Skip to content

Commit

Permalink
wip: disable few post-start functions that are done in snc
Browse files Browse the repository at this point in the history
  • Loading branch information
anjannath committed Jan 9, 2025
1 parent 9d17fbb commit 5b0562f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 78 deletions.
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 @@ 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"
)

Expand All @@ -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 {

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 @@ 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
}

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 @@ -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")
Expand Down Expand Up @@ -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 {
Expand All @@ -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")
}
Expand All @@ -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 {
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

0 comments on commit 5b0562f

Please sign in to comment.