in pkg/cmd/promote.go [88:184]
func (o *promoteCmdOptions) run(cmd *cobra.Command, args []string) error {
if err := o.validate(cmd, args); err != nil {
return err
}
name := args[0]
c, err := o.GetCmdClient()
if err != nil {
return fmt.Errorf("could not retrieve cluster client: %w", err)
}
if !o.isDryRun() {
// Skip these checks if in dry mode
opSource, err := operatorInfo(o.Context, c, o.Namespace)
if err != nil {
return fmt.Errorf("could not retrieve info for Camel K operator source: %w", err)
}
opDest, err := operatorInfo(o.Context, c, o.To)
if err != nil {
return fmt.Errorf("could not retrieve info for Camel K operator destination: %w", err)
}
err = checkOpsCompatibility(cmd, opSource, opDest)
if err != nil {
return fmt.Errorf("could not verify operators compatibility: %w", err)
}
}
promotePipe := false
var sourceIntegration *v1.Integration
// We first look if a Pipe with the name exists
sourcePipe, err := o.getPipe(c, name)
if err != nil && !k8serrors.IsNotFound(err) {
return fmt.Errorf("problems looking for Pipe "+name+": %w", err)
}
if sourcePipe != nil {
promotePipe = true
}
sourceIntegration, err = o.getIntegration(c, name)
if err != nil {
return fmt.Errorf("could not get Integration "+name+": %w", err)
}
if sourceIntegration.Status.Phase != v1.IntegrationPhaseRunning {
return fmt.Errorf("could not promote an Integration in %s status", sourceIntegration.Status.Phase)
}
// Image only mode
if o.Image {
showImageOnly(cmd, sourceIntegration)
return nil
}
if !o.isDryRun() {
// Skip these checks if in dry mode
err = o.validateDestResources(c, sourceIntegration)
if err != nil {
return fmt.Errorf("could not validate destination resources: %w", err)
}
}
// Pipe promotion
if promotePipe {
destPipe := o.editPipe(sourcePipe, sourceIntegration)
if o.OutputFormat != "" {
return showPipeOutput(cmd, destPipe, o.OutputFormat, c.GetScheme())
}
// Ensure the destination namespace has access to the source namespace images
err = addSystemPullerRoleBinding(o.Context, c, sourceIntegration.Namespace, destPipe.Namespace)
if err != nil {
return err
}
replaced, err := o.replaceResource(destPipe)
if !replaced {
fmt.Fprintln(cmd.OutOrStdout(), `Promoted Pipe "`+name+`" created`)
} else {
fmt.Fprintln(cmd.OutOrStdout(), `Promoted Pipe "`+name+`" updated`)
}
return err
}
// Plain Integration promotion
destIntegration := o.editIntegration(sourceIntegration)
if o.OutputFormat != "" {
return showIntegrationOutput(cmd, destIntegration, o.OutputFormat)
}
// Ensure the destination namespace has access to the source namespace images
err = addSystemPullerRoleBinding(o.Context, c, sourceIntegration.Namespace, destIntegration.Namespace)
if err != nil {
return err
}
replaced, err := o.replaceResource(destIntegration)
if !replaced {
fmt.Fprintln(cmd.OutOrStdout(), `Promoted Integration "`+name+`" created`)
} else {
fmt.Fprintln(cmd.OutOrStdout(), `Promoted Integration "`+name+`" updated`)
}
return err
}