-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds the following auto capabilites: discover: creates a Hardware object for each unknown worker. enrollment: creates Hardware and Workflow objects for each unknown worker. disabled: auto capabilities are disabled. Signed-off-by: Jacob Weinstock <[email protected]>
- Loading branch information
1 parent
adb13fb
commit 58196fb
Showing
4 changed files
with
165 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"github.com/tinkerbell/tink/api/v1alpha1" | ||
"github.com/tinkerbell/tink/internal/ptr" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
type AutoCapMode string | ||
|
||
var ( | ||
AutoCapModeDiscovery AutoCapMode = "discovery" | ||
AutoCapModeEnrollment AutoCapMode = "enrollment" | ||
AutoCapModeDisabled AutoCapMode = "disabled" | ||
) | ||
|
||
func (k *KubernetesBackedServer) hardwareObjectExists(ctx context.Context, workerID string) bool { | ||
if err := k.ClientFunc().Get(ctx, types.NamespacedName{Name: strings.ReplaceAll(workerID, ":", "."), Namespace: k.namespace}, &v1alpha1.Hardware{}); err != nil { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
func (k *KubernetesBackedServer) createHardwareObject(ctx context.Context, workerID string) error { | ||
hw := &v1alpha1.Hardware{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: strings.ReplaceAll(workerID, ":", "."), | ||
Namespace: k.namespace, | ||
}, | ||
Spec: v1alpha1.HardwareSpec{ | ||
Interfaces: []v1alpha1.Interface{ | ||
{ | ||
DHCP: &v1alpha1.DHCP{ | ||
MAC: workerID, | ||
}, | ||
Netboot: &v1alpha1.Netboot{ | ||
AllowPXE: ptr.Bool(true), | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
return k.ClientFunc().Create(ctx, hw) | ||
} | ||
|
||
func (k *KubernetesBackedServer) createWorkflowObject(ctx context.Context, workerID string) error { | ||
wf := &v1alpha1.Workflow{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: strings.ReplaceAll(workerID, ":", "."), | ||
Namespace: k.namespace, | ||
}, | ||
Spec: v1alpha1.WorkflowSpec{ | ||
HardwareRef: strings.ReplaceAll(workerID, ":", "."), | ||
TemplateRef: k.AutoEnrollmentTemplate, | ||
HardwareMap: map[string]string{ | ||
"device_1": workerID, | ||
}, | ||
}, | ||
} | ||
return k.ClientFunc().Create(ctx, wf) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters