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

Better labeling for 3rd party provisioners #154

Merged
merged 5 commits into from
Aug 29, 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
k8s.io/apimachinery v0.25.2
k8s.io/client-go v12.0.0+incompatible
k8s.io/code-generator v0.25.2
k8s.io/utils v0.0.0-20220922133306-665eaaec4324
)

require (
Expand Down Expand Up @@ -68,7 +69,6 @@ require (
k8s.io/gengo v0.0.0-20211129171323-c02415ce4185 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20220928191237-829ce0c27909 // indirect
k8s.io/utils v0.0.0-20220922133306-665eaaec4324 // indirect
sigs.k8s.io/controller-runtime v0.13.0 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
Expand Down
26 changes: 12 additions & 14 deletions pkg/controllers/tfpcontroller/tfpcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,10 @@ func (t *TerraformProvisionerController) processNextVM() bool {
// returns an error and a boolean of requeue
func (t *TerraformProvisionerController) handleProvision(vm *hfv1.VirtualMachine) (error, bool) {
// VM shall not be provisioned by internal terraform controller
if ! vm.Spec.Provision {
if provisionMethod, ok := vm.ObjectMeta.Labels["hobbyfarm.io/provisioner"]; ok {
if provisionMethod == "external" {
glog.V(8).Infof("vm %s ignored due to external provisioning label", vm.Name)
t.vmWorkqueue.Done(vm.Name)
}
if !vm.Spec.Provision {
if prov, ok := vm.ObjectMeta.Labels["hobbyfarm.io/provisioner"]; ok && prov != "" {
glog.V(8).Infof("vm %s ignored by internal provisioner due to 3rd party provisioning label", vm.Name)
t.vmWorkqueue.Done(vm.Name)
}
glog.V(8).Infof("vm %s was not a provisioned vm", vm.Name)
return nil, false
Expand Down Expand Up @@ -235,18 +233,18 @@ func (t *TerraformProvisionerController) handleProvision(vm *hfv1.VirtualMachine
glog.Errorf("error generating keypair %v", err)
return err, true
}
config := util.GetVMConfig(env,vmt)
config := util.GetVMConfig(env, vmt)

config["name"] = vm.Name
config["public_key"] = pubKey

image, exists := config["image"]
if !exists || image == "" {
if !exists || image == "" {
return fmt.Errorf("image does not exist or is empty in vm config for vmt %s", vmt.Name), true
}

moduleName, exists := config["module"]
if !exists || moduleName == "" {
if !exists || moduleName == "" {
return fmt.Errorf("module name does not exist or is empty in vm config for vmt %s", vmt.Name), true
}

Expand Down Expand Up @@ -297,7 +295,7 @@ func (t *TerraformProvisionerController) handleProvision(vm *hfv1.VirtualMachine
Data: map[string][]byte{
"private_key": []byte(privKey),
"public_key": []byte(pubKey),
"password" : []byte(password),
"password": []byte(password),
},
}

Expand Down Expand Up @@ -348,10 +346,10 @@ func (t *TerraformProvisionerController) handleProvision(vm *hfv1.VirtualMachine

toUpdate.Status.Status = hfv1.VmStatusProvisioned
toUpdate.Status.TFState = tfs.Name

toUpdate, updateErr := t.hfClientSet.HobbyfarmV1().VirtualMachines(util.GetReleaseNamespace()).UpdateStatus(t.ctx, toUpdate, metav1.UpdateOptions{})

if(updateErr != nil){
if updateErr != nil {
glog.Errorf("error while updating VirtualMachine status %s", toUpdate.Name)
return updateErr
}
Expand All @@ -362,7 +360,7 @@ func (t *TerraformProvisionerController) handleProvision(vm *hfv1.VirtualMachine

toUpdate, updateErr = t.hfClientSet.HobbyfarmV1().VirtualMachines(util.GetReleaseNamespace()).Update(t.ctx, toUpdate, metav1.UpdateOptions{})

if(updateErr != nil){
if updateErr != nil {
glog.Errorf("error while updating VirtualMachine %s", toUpdate.Name)
return updateErr
}
Expand Down Expand Up @@ -465,7 +463,7 @@ func (t *TerraformProvisionerController) handleProvision(vm *hfv1.VirtualMachine

toUpdate, updateErr := t.hfClientSet.HobbyfarmV1().VirtualMachines(util.GetReleaseNamespace()).Update(t.ctx, toUpdate, metav1.UpdateOptions{})

if(updateErr != nil){
if updateErr != nil {
glog.Errorf("error while updating machine: %s", toUpdate.Name)
return updateErr
}
Expand Down
Loading