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

Add virtctl to tekton task #244

Merged
merged 2 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions manifests/kubernetes/kubevirt-tekton-tasks-kubernetes.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions manifests/okd/kubevirt-tekton-tasks-okd.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions modules/create-vm/cmd/create-vm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func main() {
log.Logger().Debug("parsed arguments", zap.Reflect("cliOptions", cliOptions))

vmCreator, err := vmcreator.NewVMCreator(cliOptions)

if err != nil {
exit.ExitOrDieFromError(GenericExitCode, err)
}
Expand All @@ -41,7 +40,6 @@ func main() {
}

vm, err := vmCreator.CreateVM()

if err != nil {
exit.ExitOrDieFromError(CreateVMErrorExitCode, err,
zerrors.IsStatusError(err, http.StatusNotFound, http.StatusConflict, http.StatusUnprocessableEntity),
Expand All @@ -51,10 +49,11 @@ func main() {
if err := vmCreator.OwnVolumes(vm); err != nil {
exit.ExitFromError(OwnVolumesErrorExitCode, err)
}
runStrategy := cliOptions.GetRunStrategy()
Copy link
Member

Choose a reason for hiding this comment

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

Why drop this check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can specify the RunStrategy either through virtctl parameters or directly in a manifest. The runStrategy checked in this condition is specified separately in the task spec. If we don't use the RunStrategy parameter of a task the string will be empty and it will depend only on StartVM flag. Also StartVM should not perform any action if runStrategy of a created VM is already set to Always. - https://kubevirt.io/user-guide/virtual_machines/run_strategies/#virtctl

Copy link
Member

Choose a reason for hiding this comment

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

So this always tries to start the VM and mightt return an error from the API?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It only tries to start the VM when StartVM param is specified. It should not return error, when the VM is already running nothing happens.

if cliOptions.GetStartVMFlag() && kubevirtv1.RunStrategyAlways != kubevirtv1.VirtualMachineRunStrategy(runStrategy) {
err := vmCreator.StartVM(vm.Namespace, vm.Name)
if err != nil {

if cliOptions.GetStartVMFlag() &&
(vm.Spec.RunStrategy == nil || *vm.Spec.RunStrategy != kubevirtv1.RunStrategyAlways) &&
(vm.Spec.Running == nil || !*vm.Spec.Running) {
if err := vmCreator.StartVM(vm.Namespace, vm.Name); err != nil {
exit.ExitFromError(StartVMErrorExitCode, err)
}
}
Expand Down
30 changes: 18 additions & 12 deletions modules/create-vm/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ require (
github.com/kubevirt/kubevirt-tekton-tasks/modules/shared v0.0.0
github.com/kubevirt/kubevirt-tekton-tasks/modules/sharedtest v0.0.0
github.com/mattbaird/jsonpatch v0.0.0-20171005235357-81af80346b1a
github.com/onsi/ginkgo/v2 v2.1.6
github.com/onsi/gomega v1.20.1
github.com/onsi/ginkgo/v2 v2.2.0
github.com/onsi/gomega v1.20.2
github.com/openshift/api v0.0.0
github.com/openshift/client-go v0.0.0
go.uber.org/zap v1.19.1
k8s.io/api v0.25.2
k8s.io/apimachinery v0.25.2
k8s.io/client-go v12.0.0+incompatible
kubevirt.io/api v0.59.0
kubevirt.io/client-go v0.59.0
kubevirt.io/api v1.0.0-alpha.0
kubevirt.io/client-go v1.0.0-alpha.0
kubevirt.io/containerized-data-importer v1.55.0
kubevirt.io/containerized-data-importer-api v1.55.0
kubevirt.io/kubevirt v1.0.0-alpha.0
sigs.k8s.io/yaml v1.3.0
)

Expand All @@ -37,41 +38,45 @@ require (
github.com/go-openapi/swag v0.21.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/k8snetworkplumbingwg/network-attachment-definition-client v0.0.0-20191119172530-79f836b90111 // indirect
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.3.0 // indirect
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/openshift/custom-resource-status v1.1.2 // indirect
github.com/pborman/uuid v1.2.0 // indirect
github.com/spf13/cobra v1.5.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/goleak v1.1.12 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/net v0.6.0 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.23.5 // indirect
k8s.io/klog/v2 v2.70.1 // indirect
k8s.io/kube-aggregator v0.23.5 // indirect
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
kubevirt.io/controller-lifecycle-operator-sdk/api v0.0.0-20220329064328-f3cc58c6ed90 // indirect
Expand All @@ -88,6 +93,7 @@ replace (
k8s.io/apimachinery => k8s.io/apimachinery v0.24.6
k8s.io/client-go => k8s.io/client-go v0.24.6
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.24.6
k8s.io/kubectl => k8s.io/kubectl v0.23.5
)

// CDI
Expand Down
Loading
Loading