Skip to content

Commit

Permalink
Merge pull request #70 from chrisdoherty4/feat/machine-ref
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdoherty4 authored Dec 2, 2022
2 parents 3a8af4c + 4009476 commit c010b59
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
12 changes: 10 additions & 2 deletions api/v1alpha1/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package v1alpha1
import (
"fmt"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -35,11 +34,20 @@ const (
JobRunning JobConditionType = "Running"
)

// MachineRef is used to reference a Machine object.
type MachineRef struct {
// Name of the Machine.
Name string `json:"name"`

// Namespace the Machine resides in.
Namespace string `json:"namespace"`
}

// JobSpec defines the desired state of Job
type JobSpec struct {
// MachineRef represents the Machine resource to execute the job.
// All the tasks in the job are executed for the same Machine.
MachineRef corev1.ObjectReference `json:"machineRef"`
MachineRef MachineRef `json:"machineRef"`

// Tasks represents a list of baseboard management actions to be executed.
// The tasks are executed sequentially. Controller waits for one task to complete before executing the next.
Expand Down
3 changes: 1 addition & 2 deletions controllers/job_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -171,7 +170,7 @@ func (r *JobReconciler) reconcile(ctx context.Context, job *bmcv1alpha1.Job, job
}

// getMachine Gets the Machine from MachineRef
func (r *JobReconciler) getMachine(ctx context.Context, reference corev1.ObjectReference, machine *bmcv1alpha1.Machine) error {
func (r *JobReconciler) getMachine(ctx context.Context, reference bmcv1alpha1.MachineRef, machine *bmcv1alpha1.Machine) error {
key := types.NamespacedName{Namespace: reference.Namespace, Name: reference.Name}
err := r.client.Get(ctx, key, machine)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions controllers/job_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/onsi/gomega"
bmcv1alpha1 "github.com/tinkerbell/rufio/api/v1alpha1"
"github.com/tinkerbell/rufio/controllers"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -55,7 +54,7 @@ func TestJobReconciler_UnknownMachine(t *testing.T) {
Name: "test",
},
Spec: bmcv1alpha1.JobSpec{
MachineRef: corev1.ObjectReference{Name: "unknown", Namespace: "default"},
MachineRef: bmcv1alpha1.MachineRef{Name: "unknown", Namespace: "default"},
Tasks: []bmcv1alpha1.Action{},
},
}
Expand Down Expand Up @@ -151,7 +150,7 @@ func createJob(name string, machine *bmcv1alpha1.Machine) *bmcv1alpha1.Job {
Name: name,
},
Spec: bmcv1alpha1.JobSpec{
MachineRef: corev1.ObjectReference{Name: machine.Name, Namespace: machine.Namespace},
MachineRef: bmcv1alpha1.MachineRef{Name: machine.Name, Namespace: machine.Namespace},
Tasks: []bmcv1alpha1.Action{},
},
}
Expand Down

0 comments on commit c010b59

Please sign in to comment.