Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit 00f0364

Browse files
committed
WIP
1 parent fe2bd39 commit 00f0364

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

operator/api/v1/target_types.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,29 @@ import (
2323
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
2424
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
2525

26+
// TargetType defines the Type of the Target
27+
// +kubebuilder:validation:Enum=Host;IPRange;Domain
28+
type TargetType string
29+
2630
// TargetSpec defines the desired state of Target
2731
type TargetSpec struct {
2832
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
2933
// Important: Run "make" to regenerate code after modifying this file
34+
Type TargetType `json:"type,omitempty"`
3035

3136
// Foo is an example field of Target. Edit Target_types.go to remove/update
32-
Foo string `json:"foo,omitempty"`
37+
Address string `json:"address,omitempty"`
3338
}
3439

3540
// TargetStatus defines the observed state of Target
3641
type TargetStatus struct {
3742
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
3843
// Important: Run "make" to regenerate code after modifying this file
44+
State string `json:"state,omitempty"`
3945
}
4046

4147
// +kubebuilder:object:root=true
48+
// +kubebuilder:subresource:status
4249

4350
// Target is the Schema for the targets API
4451
type Target struct {

operator/controllers/target_controller.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,32 @@ type TargetReconciler struct {
3838
// +kubebuilder:rbac:groups=scans.experimental.securecodebox.io,resources=targets/status,verbs=get;update;patch
3939

4040
func (r *TargetReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
41-
_ = context.Background()
42-
_ = r.Log.WithValues("target", req.NamespacedName)
41+
ctx := context.Background()
42+
log := r.Log.WithValues("target", req.NamespacedName)
4343

4444
// your logic here
4545

46+
log.Info("Starting Target Reconciler")
47+
48+
var target scansv1.Target
49+
err := r.Get(ctx, req.NamespacedName, &target)
50+
if err != nil {
51+
return ctrl.Result{}, client.IgnoreNotFound(err)
52+
}
53+
54+
if target.Status.State == "" {
55+
target.Status.State = "Scanning"
56+
}
57+
switch target.Status.State {
58+
case "Scanning":
59+
switch target.Spec.Type {
60+
case "Host":
61+
62+
}
63+
case "Sleeping":
64+
// TODO: Reschedule
65+
}
66+
4667
return ctrl.Result{}, nil
4768
}
4869

0 commit comments

Comments
 (0)