Skip to content

Commit

Permalink
feat: implement phase and columns
Browse files Browse the repository at this point in the history
  • Loading branch information
yyewolf committed Oct 24, 2024
1 parent 6588635 commit 9c5029d
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 4 deletions.
6 changes: 6 additions & 0 deletions api/v1/challenge_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,18 @@ type ChallengeSpec struct {

// ChallengeStatus defines the observed state of Challenge
type ChallengeStatus struct {
Phase string `json:"phase"`
Error string `json:"error"`
}

// Challenge is the Schema for the challenges API
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
// +kubebuilder:printcolumn:name="Category",type="string",JSONPath=".spec.category"
// +kubebuilder:printcolumn:name="Initial Value",type="integer",JSONPath=".spec.initial_value"
// +kubebuilder:printcolumn:name="Min Value",type="integer",JSONPath=".spec.minimum_value"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
type Challenge struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions api/v1/globally_instanced_challenge_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ type GloballyInstancedChallengeSpec struct {

// GloballyInstancedChallenge is the Schema for the GlobalChallenges API
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
// +kubebuilder:printcolumn:name="Category",type="string",JSONPath=".spec.category"
// +kubebuilder:printcolumn:name="Initial Value",type="integer",JSONPath=".spec.initial_value"
// +kubebuilder:printcolumn:name="Min Value",type="integer",JSONPath=".spec.minimum_value"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
type GloballyInstancedChallenge struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions api/v1/instanced_challenge_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ type InstancedChallengeSpec struct {

// InstancedChallenge is the Schema for the challenges API
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
// +kubebuilder:printcolumn:name="Category",type="string",JSONPath=".spec.category"
// +kubebuilder:printcolumn:name="Initial Value",type="integer",JSONPath=".spec.initial_value"
// +kubebuilder:printcolumn:name="Min Value",type="integer",JSONPath=".spec.minimum_value"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
type InstancedChallenge struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions api/v1/oracle_instanced_challenge_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ type OracleInstancedChallengeSpec struct {

// OracleInstancedChallenge is the Schema for the oraclechallenges API
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
// +kubebuilder:printcolumn:name="Category",type="string",JSONPath=".spec.category"
// +kubebuilder:printcolumn:name="Initial Value",type="integer",JSONPath=".spec.initial_value"
// +kubebuilder:printcolumn:name="Min Value",type="integer",JSONPath=".spec.minimum_value"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
type OracleInstancedChallenge struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
21 changes: 20 additions & 1 deletion config/crd/bases/i.4ts.fr_challenges.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,23 @@ spec:
singular: challenge
scope: Namespaced
versions:
- name: v1
- additionalPrinterColumns:
- jsonPath: .status.phase
name: Phase
type: string
- jsonPath: .spec.category
name: Category
type: string
- jsonPath: .spec.initial_value
name: Initial Value
type: integer
- jsonPath: .spec.minimum_value
name: Min Value
type: integer
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1
schema:
openAPIV3Schema:
properties:
Expand Down Expand Up @@ -120,8 +136,11 @@ spec:
properties:
error:
type: string
phase:
type: string
required:
- error
- phase
type: object
type: object
served: true
Expand Down
21 changes: 20 additions & 1 deletion config/crd/bases/i.4ts.fr_globallyinstancedchallenges.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,23 @@ spec:
singular: globallyinstancedchallenge
scope: Namespaced
versions:
- name: v1
- additionalPrinterColumns:
- jsonPath: .status.phase
name: Phase
type: string
- jsonPath: .spec.category
name: Category
type: string
- jsonPath: .spec.initial_value
name: Initial Value
type: integer
- jsonPath: .spec.minimum_value
name: Min Value
type: integer
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1
schema:
openAPIV3Schema:
properties:
Expand Down Expand Up @@ -3767,8 +3783,11 @@ spec:
properties:
error:
type: string
phase:
type: string
required:
- error
- phase
type: object
type: object
served: true
Expand Down
21 changes: 20 additions & 1 deletion config/crd/bases/i.4ts.fr_instancedchallenges.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,23 @@ spec:
singular: instancedchallenge
scope: Namespaced
versions:
- name: v1
- additionalPrinterColumns:
- jsonPath: .status.phase
name: Phase
type: string
- jsonPath: .spec.category
name: Category
type: string
- jsonPath: .spec.initial_value
name: Initial Value
type: integer
- jsonPath: .spec.minimum_value
name: Min Value
type: integer
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1
schema:
openAPIV3Schema:
properties:
Expand Down Expand Up @@ -3750,8 +3766,11 @@ spec:
properties:
error:
type: string
phase:
type: string
required:
- error
- phase
type: object
type: object
served: true
Expand Down
21 changes: 20 additions & 1 deletion config/crd/bases/i.4ts.fr_oracleinstancedchallenges.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,23 @@ spec:
singular: oracleinstancedchallenge
scope: Namespaced
versions:
- name: v1
- additionalPrinterColumns:
- jsonPath: .status.phase
name: Phase
type: string
- jsonPath: .spec.category
name: Category
type: string
- jsonPath: .spec.initial_value
name: Initial Value
type: integer
- jsonPath: .spec.minimum_value
name: Min Value
type: integer
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1
schema:
openAPIV3Schema:
properties:
Expand Down Expand Up @@ -3767,8 +3783,11 @@ spec:
properties:
error:
type: string
phase:
type: string
required:
- error
- phase
type: object
type: object
served: true
Expand Down
23 changes: 23 additions & 0 deletions internal/controllers/k8s_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (r *InstancierReconciler) Register(ctx context.Context, req ctrl.Request) (
r.UnregisterChallenge(&challenge)
return ctrl.Result{}, nil
}
challenge.Status.Phase = "Syncing"
r.RegisterChallenge(&challenge)
return ctrl.Result{}, nil
}
Expand All @@ -95,6 +96,7 @@ func (r *InstancierReconciler) Register(ctx context.Context, req ctrl.Request) (
r.UnregisterChallenge(&instancedChallenge)
return ctrl.Result{}, nil
}
instancedChallenge.Status.Phase = "Syncing"
r.RegisterChallenge(&instancedChallenge)
return ctrl.Result{}, nil
}
Expand All @@ -106,10 +108,23 @@ func (r *InstancierReconciler) Register(ctx context.Context, req ctrl.Request) (
r.UnregisterChallenge(&oracleInstancedChallenge)
return ctrl.Result{}, nil
}
oracleInstancedChallenge.Status.Phase = "Syncing"
r.RegisterChallenge(&oracleInstancedChallenge)
return ctrl.Result{}, nil
}

var globallyInstancedChallenge v1.GloballyInstancedChallenge
err = r.Get(ctx, req.NamespacedName, &globallyInstancedChallenge)
if err == nil {
if globallyInstancedChallenge.DeletionTimestamp != nil {
r.UnregisterChallenge(&globallyInstancedChallenge)
return ctrl.Result{}, nil
}
globallyInstancedChallenge.Status.Phase = "Syncing"
r.RegisterChallenge(&globallyInstancedChallenge)
return ctrl.Result{}, nil
}

logrus.WithField("name", req.Name).Warn("Ressource deleted, rechecking")
r.Reinit()

Expand All @@ -133,8 +148,10 @@ func (r *InstancierReconciler) ReconcileCTFd() error {
}
r.Get(context.Background(), client.ObjectKeyFromObject(&obj), &obj)
obj.Status.Error = ""
obj.Status.Phase = "Synced"
if found {
obj.Status.Error = err.Error()
obj.Status.Phase = "Error"
}
r.Status().Update(context.Background(), &obj)
case *v1.InstancedChallenge:
Expand All @@ -143,8 +160,10 @@ func (r *InstancierReconciler) ReconcileCTFd() error {
}
r.Get(context.Background(), client.ObjectKeyFromObject(&obj), &obj)
obj.Status.Error = ""
obj.Status.Phase = "Synced"
if found {
obj.Status.Error = err.Error()
obj.Status.Phase = "Error"
}
r.Status().Update(context.Background(), &obj)
case *v1.GloballyInstancedChallenge:
Expand All @@ -153,8 +172,10 @@ func (r *InstancierReconciler) ReconcileCTFd() error {
}
r.Get(context.Background(), client.ObjectKeyFromObject(&obj), &obj)
obj.Status.Error = ""
obj.Status.Phase = "Synced"
if found {
obj.Status.Error = err.Error()
obj.Status.Phase = "Error"
}
r.Status().Update(context.Background(), &obj)
case *v1.OracleInstancedChallenge:
Expand All @@ -163,8 +184,10 @@ func (r *InstancierReconciler) ReconcileCTFd() error {
}
r.Get(context.Background(), client.ObjectKeyFromObject(&obj), &obj)
obj.Status.Error = ""
obj.Status.Phase = "Synced"
if found {
obj.Status.Error = err.Error()
obj.Status.Phase = "Error"
}
r.Status().Update(context.Background(), &obj)
}
Expand Down

0 comments on commit 9c5029d

Please sign in to comment.