github.com/crossplane/upjet@v1.3.0/pkg/migration/exec_steps.go (about)

     1  // SPDX-FileCopyrightText: 2023 The Crossplane Authors <https://crossplane.io>
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package migration
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"github.com/pkg/errors"
    11  )
    12  
    13  func (pg *PlanGenerator) stepBackupAllResources() {
    14  	pg.stepBackupManagedResources()
    15  	pg.stepBackupCompositeResources()
    16  	pg.stepBackupClaims()
    17  }
    18  
    19  func (pg *PlanGenerator) stepBackupManagedResources() {
    20  	s := pg.stepConfiguration(stepBackupMRs)
    21  	s.Exec.Args = []string{"-c", "kubectl get managed -o yaml > backup/managed-resources.yaml"}
    22  }
    23  
    24  func (pg *PlanGenerator) stepBackupCompositeResources() {
    25  	s := pg.stepConfiguration(stepBackupComposites)
    26  	s.Exec.Args = []string{"-c", "kubectl get composite -o yaml > backup/composite-resources.yaml"}
    27  }
    28  
    29  func (pg *PlanGenerator) stepBackupClaims() {
    30  	s := pg.stepConfiguration(stepBackupClaims)
    31  	s.Exec.Args = []string{"-c", "kubectl get claim --all-namespaces -o yaml > backup/claim-resources.yaml"}
    32  }
    33  
    34  func (pg *PlanGenerator) stepCheckHealthOfNewProvider(source UnstructuredWithMetadata, targets []*UnstructuredWithMetadata) error {
    35  	for _, t := range targets {
    36  		var s *Step
    37  		isFamilyConfig, err := checkContainsFamilyConfigProvider(targets)
    38  		if err != nil {
    39  			return errors.Wrapf(err, "could not decide whether the provider family config")
    40  		}
    41  		if isFamilyConfig {
    42  			s = pg.stepConfigurationWithSubStep(stepCheckHealthFamilyProvider, true)
    43  		} else {
    44  			s = pg.stepConfigurationWithSubStep(stepCheckHealthNewServiceScopedProvider, true)
    45  		}
    46  		s.Exec.Args = []string{"-c", fmt.Sprintf("kubectl wait provider.pkg %s --for condition=Healthy", t.Object.GetName())}
    47  		t.Object.Object = addGVK(source.Object, t.Object.Object)
    48  		t.Metadata.Path = fmt.Sprintf("%s/%s.yaml", s.Name, getVersionedName(t.Object))
    49  	}
    50  	return nil
    51  }
    52  
    53  func (pg *PlanGenerator) stepCheckInstallationOfNewProvider(source UnstructuredWithMetadata, targets []*UnstructuredWithMetadata) error {
    54  	for _, t := range targets {
    55  		var s *Step
    56  		isFamilyConfig, err := checkContainsFamilyConfigProvider(targets)
    57  		if err != nil {
    58  			return errors.Wrapf(err, "could not decide whether the provider family config")
    59  		}
    60  		if isFamilyConfig {
    61  			s = pg.stepConfigurationWithSubStep(stepCheckInstallationFamilyProviderRevision, true)
    62  		} else {
    63  			s = pg.stepConfigurationWithSubStep(stepCheckInstallationServiceScopedProviderRevision, true)
    64  		}
    65  		s.Exec.Args = []string{"-c", fmt.Sprintf("kubectl wait provider.pkg %s --for condition=Installed", t.Object.GetName())}
    66  		t.Object.Object = addGVK(source.Object, t.Object.Object)
    67  		t.Metadata.Path = fmt.Sprintf("%s/%s.yaml", s.Name, getVersionedName(t.Object))
    68  	}
    69  	return nil
    70  }
    71  
    72  func (pg *PlanGenerator) stepBuildConfiguration() {
    73  	s := pg.stepConfiguration(stepBuildConfiguration)
    74  	s.Exec.Args = []string{"-c", "up xpkg build --package-root={{PKG_ROOT}} --examples-root={{EXAMPLES_ROOT}} -o {{PKG_PATH}}"}
    75  }
    76  
    77  func (pg *PlanGenerator) stepPushConfiguration() {
    78  	s := pg.stepConfiguration(stepPushConfiguration)
    79  	s.Exec.Args = []string{"-c", "up xpkg push {{TARGET_CONFIGURATION_PACKAGE}} -f {{PKG_PATH}}"}
    80  }