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

.werft/build: Refactor installer steps into dedicated class #8884

Merged
merged 4 commits into from
Mar 30, 2022

Conversation

ArthurSens
Copy link
Contributor

@ArthurSens ArthurSens commented Mar 18, 2022

Description

This PR tries to reduce amount of code under .werft/jobs/build/deploy-to-preview-environments.ts by moving all code related to installer to a dedicated Installer interface.

That way, we can make the deploy phase as simple as:

werft.phase(deploy)
const installer = newInstaller(params...)
try {
        installer.init(installerSlices.INSTALLER_INIT)
        installer.addPreviewConfiguration(installerSlices.PREVIEW_CONFIG)
        installer.validateConfiguration(installerSlices.VALIDATE_CONFIG)
        installer.render(installerSlices.INSTALLER_RENDER)
        installer.postProcessing(installerSlices.INSTALLER_POST_PROCESSING)
        installer.install(installerSlices.APPLY_INSTALL_MANIFESTS)
    } catch (err) {
        if (!jobConfig.mainBuild) {
            werft.fail(phases.DEPLOY, err)
        }
        exec('exit 0')
    }
werft.done(deploy)

I'm opening it as a draft just to collect early feedback on the approach. @gitpod-io/platform do you agree with the approach here?

How to test

  • Start a preview on core-dev and make sure workspaces start
  • Start a preview on Harvester and make sure workspaces start

Release Notes

NONE

Signed-off-by: ArthurSens <arthursens2005@gmail.com>
@ArthurSens
Copy link
Contributor Author

/werft run with-vm=true

@ArthurSens
Copy link
Contributor Author

ArthurSens commented Mar 18, 2022

Tested on both core-dev and Harvester, so turning it into ready for review 🙂

@ArthurSens ArthurSens marked this pull request as ready for review March 18, 2022 16:06
@ArthurSens ArthurSens requested a review from a team March 18, 2022 16:06
@stale
Copy link

stale bot commented Mar 29, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the meta: stale This issue/PR is stale and will be closed soon label Mar 29, 2022
Copy link
Contributor

@mads-hartmann mads-hartmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome Arthur. I think this could be improved further, I have left some comments in the review. I'm happy to talk through this more if that's helpful ☺️

.werft/jobs/build/installer/installer.ts Outdated Show resolved Hide resolved
.werft/jobs/build/installer/installer.ts Outdated Show resolved Hide resolved
.werft/jobs/build/installer/installer.ts Outdated Show resolved Hide resolved
.werft/jobs/build/installer/installer.ts Outdated Show resolved Hide resolved
@stale stale bot removed meta: stale This issue/PR is stale and will be closed soon labels Mar 29, 2022
Signed-off-by: ArthurSens <arthursens2005@gmail.com>
@ArthurSens
Copy link
Contributor Author

ArthurSens commented Mar 29, 2022

Thanks for all the Typescript tips Mads, the CI is still re-running but I believe I was able to do the refactoring using class and private methods 🙂

Learned a lot!

@ArthurSens ArthurSens changed the title .werft/build: Refactor installer steps into dedicated interface .werft/build: Refactor installer steps into dedicated class Mar 29, 2022
mads-hartmann
mads-hartmann previously approved these changes Mar 30, 2022
Copy link
Contributor

@mads-hartmann mads-hartmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few comments that you can follow up on in a later PR ☺️ I added the hold label in case you needed to do some last testing before merging

import { Werft } from "../../../util/werft";
import { getNodePoolIndex } from "../deploy-to-preview-environment";

const blockNewUserConfigPath = './blockNewUsers';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We don't (as far as I know) have a convention to use upper or lower case for constants like these, but it would be nice to be consistent within the file. So either make these uppercase of make the uppercase ones lowercase ☺️

workspaceFeatureFlags: string[]
gitpodDaemonsetPorts: GitpodDaemonsetPorts

constructor(werft: Werft, configPath: string, version: string, proxySecretName: string, domain: string, previewName: string, imagePullSecretName: string, deploymentNamespace: string, analytics: Analytics, withEELicense: boolean, withVM: boolean, workspaceFeatureFlags: string[], gitpodDaemonsetPorts: GitpodDaemonsetPorts) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you have a method/function that takes a lot of arguments I usually prefer to use an "options" argument instead (just as you have previously done here.) I has a few benefits

  1. It becomes easier to read what the arguments are as they're named when you invoke the function. This is nice when you're reading code in a PR and not in your editor.
  2. It's easier to add new arguments as you don't have to worry about the order.

So in this case it would look like this

export type InstallerOptions = {
  werft: Werft
  configPath: string
  // all the rest
}

export class Installer {
  // All your private members
  
  constructor(options: InstallerOptions) {
    this.werft = options.werft
    // all the rest
  }
}

And then when you invoke it

new Installer({
  werft: werft,
  configPath: configPath,
  /// and so on
})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice, I really wasn't enjoying that method signature 😅

I'll change that real quick

Signed-off-by: ArthurSens <arthursens2005@gmail.com>
Signed-off-by: ArthurSens <arthursens2005@gmail.com>
Copy link
Contributor

@mads-hartmann mads-hartmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, looks great 🛹

@roboquat roboquat merged commit 264df6a into main Mar 30, 2022
@roboquat roboquat deleted the as/clean-installer-deploy branch March 30, 2022 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants