@@ -397,7 +397,7 @@ func preRunInstallCommon(cmd *cobra.Command, flags *InstallCmdFlags, rc runtimec
397397 flags .licenseBytes = b
398398
399399 // validate the the license is indeed a license file
400- l , err := helpers .ParseLicense ( flags . licenseFile )
400+ l , err := helpers .ParseLicenseFromBytes ( b )
401401 if err != nil {
402402 var notALicenseFileErr helpers.ErrNotALicenseFile
403403 if errors .As (err , & notALicenseFileErr ) {
@@ -425,6 +425,22 @@ func preRunInstallCommon(cmd *cobra.Command, flags *InstallCmdFlags, rc runtimec
425425 flags .airgapMetadata = metadata
426426 }
427427
428+ // sync the license if we are in the manager experience and a license is provided and we are
429+ // not in airgap mode
430+ if flags .enableManagerExperience && flags .license != nil && ! flags .isAirgap {
431+ replicatedAPI , err := newReplicatedAPIClient (flags .license , flags .clusterID )
432+ if err != nil {
433+ return fmt .Errorf ("failed to create replicated API client: %w" , err )
434+ }
435+
436+ updatedLicense , licenseBytes , err := syncLicense (cmd .Context (), replicatedAPI , flags .license )
437+ if err != nil {
438+ return fmt .Errorf ("failed to sync license: %w" , err )
439+ }
440+ flags .license = updatedLicense
441+ flags .licenseBytes = licenseBytes
442+ }
443+
428444 var err error
429445 flags .embeddedAssetsSize , err = goods .SizeOfEmbeddedAssets ()
430446 if err != nil {
@@ -627,22 +643,6 @@ func runManagerExperienceInstall(
627643 return fmt .Errorf ("get kotsadm namespace: %w" , err )
628644 }
629645
630- replicatedAPI , err := newReplicatedAPIClient (flags .license , flags .clusterID )
631- if err != nil {
632- return fmt .Errorf ("failed to create replicated API client: %w" , err )
633- }
634-
635- // Sync license before starting the manager experience (online only)
636- isAirgap := flags .airgapBundle != ""
637- if ! isAirgap {
638- updatedLicense , licenseBytes , err := syncLicense (ctx , replicatedAPI , flags .license )
639- if err != nil {
640- return fmt .Errorf ("failed to sync license: %w" , err )
641- }
642- flags .license = updatedLicense
643- flags .licenseBytes = licenseBytes
644- }
645-
646646 // this is necessary because the api listens on all interfaces,
647647 // and we only know the interface to use when the user selects it in the ui
648648 ipAddresses , err := netutils .ListAllValidIPAddresses ()
@@ -913,7 +913,7 @@ func verifyAndPrompt(ctx context.Context, cmd *cobra.Command, appSlug string, fl
913913 }
914914
915915 logrus .Debugf ("checking license matches" )
916- license , err := getLicenseFromFilepath (flags .licenseFile )
916+ license , err := verifyLicense (flags .license )
917917 if err != nil {
918918 return err
919919 }
@@ -985,29 +985,24 @@ func ensureAdminConsolePassword(flags *InstallCmdFlags) error {
985985 return nil
986986}
987987
988- func getLicenseFromFilepath ( licenseFile string ) (* kotsv1beta1.License , error ) {
988+ func verifyLicense ( license * kotsv1beta1. License ) (* kotsv1beta1.License , error ) {
989989 rel := release .GetChannelRelease ()
990990
991991 // handle the three cases that do not require parsing the license file
992992 // 1. no release and no license, which is OK
993993 // 2. no license and a release, which is not OK
994994 // 3. a license and no release, which is not OK
995- if rel == nil && licenseFile == "" {
995+ if rel == nil && license == nil {
996996 // no license and no release, this is OK
997997 return nil , nil
998- } else if rel == nil && licenseFile != "" {
998+ } else if rel == nil && license != nil {
999999 // license is present but no release, this means we would install without vendor charts and k0s overrides
10001000 return nil , fmt .Errorf ("a license was provided but no release was found in binary, please rerun without the license flag" )
1001- } else if rel != nil && licenseFile == "" {
1001+ } else if rel != nil && license == nil {
10021002 // release is present but no license, this is not OK
10031003 return nil , fmt .Errorf ("no license was provided for %s and one is required, please rerun with '--license <path to license file>'" , rel .AppSlug )
10041004 }
10051005
1006- license , err := helpers .ParseLicense (licenseFile )
1007- if err != nil {
1008- return nil , fmt .Errorf ("failed to parse the license file at %q, please ensure it is not corrupt: %w" , licenseFile , err )
1009- }
1010-
10111006 // Check if the license matches the application version data
10121007 if rel .AppSlug != license .Spec .AppSlug {
10131008 // if the app is different, we will not be able to provide the correct vendor supplied charts and k0s overrides
0 commit comments