• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openshift-kni / lifecycle-agent / 567839dabd85027fcc379712ab73d3ce3dd9d8a8

20 May 2026 04:08PM UTC coverage: 30.271% (+0.5%) from 29.8%
567839dabd85027fcc379712ab73d3ce3dd9d8a8

push

web-flow
Merge pull request #6318 from sebrandon1/CNF-23417

CNF-23417: Add unit tests for rollback handlers

4920 of 16253 relevant lines covered (30.27%)

0.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lca-cli/cmd/create.go
1
/*
2
Copyright 2023.
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
package cmd
18

19
import (
20
        "fmt"
21

22
        ibuv1 "github.com/openshift-kni/lifecycle-agent/api/imagebasedupgrade/v1"
23
        v1 "github.com/openshift/api/config/v1"
24
        mcv1 "github.com/openshift/api/machineconfiguration/v1"
25
        operatorv1alpha1 "github.com/openshift/api/operator/v1alpha1"
26
        operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
27
        "github.com/spf13/cobra"
28
        "k8s.io/apimachinery/pkg/runtime"
29
        utilruntime "k8s.io/apimachinery/pkg/util/runtime"
30
        clientgoscheme "k8s.io/client-go/kubernetes/scheme"
31
        "k8s.io/client-go/tools/clientcmd"
32
        runtimeClient "sigs.k8s.io/controller-runtime/pkg/client"
33

34
        "github.com/openshift-kni/lifecycle-agent/internal/common"
35
        "github.com/openshift-kni/lifecycle-agent/lca-cli/ops"
36
        ostree "github.com/openshift-kni/lifecycle-agent/lca-cli/ostreeclient"
37
        "github.com/openshift-kni/lifecycle-agent/lca-cli/seedcreator"
38
        "github.com/openshift-kni/lifecycle-agent/lca-cli/seedrestoration"
39
)
40

41
var (
42
        scheme = runtime.NewScheme()
43

44
        // authFile is the path to the registry credentials used to push the OCI image
45
        authFile string
46

47
        // containerRegistry is the registry to push the OCI image
48
        containerRegistry string
49

50
        // recertContainerImage is the container image for the recert tool
51
        recertContainerImage string
52
        recertSkipValidation bool
53

54
        skipCleanup bool
55
)
56

57
func init() {
×
58
        utilruntime.Must(clientgoscheme.AddToScheme(scheme))
×
59
        utilruntime.Must(v1.AddToScheme(scheme))
×
60
        utilruntime.Must(mcv1.AddToScheme(scheme))
×
61
        utilruntime.Must(operatorv1alpha1.AddToScheme(scheme))
×
62
        utilruntime.Must(operatorsv1alpha1.AddToScheme(scheme))
×
63
        utilruntime.Must(ibuv1.AddToScheme(scheme))
×
64
        //+kubebuilder:scaffold:scheme
×
65
}
×
66

67
// createCmd represents the create command
68
var createCmd = &cobra.Command{
69
        Use:   "create",
70
        Short: "Create OCI image and push it to a container registry.",
71
        Run: func(cmd *cobra.Command, args []string) {
×
72
                if err := create(); err != nil {
×
73
                        log.Fatalf("Error executing create command: %v", err)
×
74
                }
×
75
        },
76
}
77

78
func init() {
×
79

×
80
        // Add create command
×
81
        rootCmd.AddCommand(createCmd)
×
82

×
83
        // Add flags to create command
×
84
        addCommonFlags(createCmd)
×
85
}
×
86

87
func create() error {
×
88

×
89
        var err error
×
90
        log.Info("OCI image creation has started")
×
91

×
92
        hostCommandsExecutor := ops.NewNsenterExecutor(log, true)
×
93
        op := ops.NewOps(log, hostCommandsExecutor)
×
94
        rpmOstreeClient := ostree.NewClient("lca-cli", hostCommandsExecutor)
×
95

×
96
        if !skipCleanup {
×
97
                defer func() {
×
98
                        if err = seedrestoration.NewSeedRestoration(log, op, common.BackupDir, containerRegistry,
×
99
                                authFile, recertContainerImage, recertSkipValidation).RestoreSeedCluster(); err != nil {
×
100
                                log.Fatalf("Failed to restore seed cluster: %v", err)
×
101
                        }
×
102
                        log.Info("Seed cluster restored successfully!")
×
103
                }()
104
        }
105

106
        config, err := clientcmd.BuildConfigFromFlags("", common.KubeconfigFile)
×
107
        if err != nil {
×
108
                return fmt.Errorf("failed to create k8s config: %w", err)
×
109
        }
×
110

111
        client, err := runtimeClient.New(config, runtimeClient.Options{Scheme: scheme})
×
112
        if err != nil {
×
113
                return fmt.Errorf("failed to create runtime client: %w", err)
×
114
        }
×
115

116
        seedCreator := seedcreator.NewSeedCreator(client, log, op, rpmOstreeClient, common.BackupDir, common.KubeconfigFile,
×
117
                containerRegistry, authFile, recertContainerImage, recertSkipValidation)
×
118
        if err = seedCreator.CreateSeedImage(); err != nil {
×
119
                err = fmt.Errorf("failed to create seed image: %w", err)
×
120
                log.Error(err)
×
121
                return err
×
122
        }
×
123

124
        log.Info("OCI image created successfully!")
×
125
        return nil
×
126
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc