Skip to content

Commit

Permalink
update kuid ref
Browse files Browse the repository at this point in the history
  • Loading branch information
henderiw committed Oct 30, 2024
1 parent 2bf690f commit 1e92e14
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 195 deletions.
12 changes: 7 additions & 5 deletions apis/choreo/v1alpha1/reconciler_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@ import (

// ReconcilerSpec defines the desired state of Reconciler
type ReconcilerSpec struct {
// ConditionType defines the condition used by this reconciler to reflect the status of its operation
ConditionType *string `json:"conditionType,omitempty" protobuf:"bytes,1,opt,name=conditionType"`
// For defines the resource and business logic of the reconciler for this Reconciler.
For ReconcilerResource `json:"for" protobuf:"bytes,1,opt,name=for"`
For ReconcilerResource `json:"for" protobuf:"bytes,2,opt,name=for"`
// Owns define the child resources this Reconciler generates as part of its business logic.
// The For resource of this Reconciler owns the derived child resources.
// The OwnerReferences are set by the internal reconciler logic. Changes to any of these resources
// will trigger the Reconciler reconciler
Owns []*ReconcilerResource `json:"owns,omitempty" protobuf:"bytes,2,rep,name=owns"`
Owns []*ReconcilerResource `json:"owns,omitempty" protobuf:"bytes,3,rep,name=owns"`
// Watches defines the resources on which the main reconciler can be retriggered. The pipeline/business logic
// determines if the reconciler is to be retriggered.
Watches []*ReconcilerResource `json:"watches,omitempty" protobuf:"bytes,3,opt,name=watches"`
Watches []*ReconcilerResource `json:"watches,omitempty" protobuf:"bytes,4,opt,name=watches"`
// Type defines the software technology this library contains
Type *SoftwardTechnologyType `json:"type,omitempty" protobuf:"bytes,4,opt,name=type"`
Type *SoftwardTechnologyType `json:"type,omitempty" protobuf:"bytes,5,opt,name=type"`
// Code supporting the reconciler
Code map[string]string `json:"code,omitempty" protobuf:"bytes,5,rep,name=code"`
Code map[string]string `json:"code,omitempty" protobuf:"bytes,6,rep,name=code"`
}

type ReconcilerResource struct {
Expand Down
5 changes: 5 additions & 0 deletions apis/choreo/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions artifacts/choreo.kform.dev_reconcilers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ spec:
type: string
description: Code supporting the reconciler
type: object
conditionType:
description: ConditionType defines the condition used by this reconciler
to reflect the status of its operation
type: string
for:
description: For defines the resource and business logic of the reconciler
for this Reconciler.
Expand Down
9 changes: 2 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ go 1.23.0

toolchain go1.23.2

//replace github.com/henderiw/apiserver-builder => github.com/henderiw/apiserver-builder v0.0.1
replace github.com/kuidio/kuid => /Users/henderiw/code/kuidio/kuid

replace github.com/henderiw/store => /Users/henderiw/code/tmp/store

require (
github.com/adrg/xdg v0.5.0
github.com/flosch/pongo2/v6 v6.0.0
Expand All @@ -19,9 +14,9 @@ require (
github.com/google/uuid v1.6.0
github.com/henderiw/iputil v0.0.0-20231218081610-37f78ad9c81c
github.com/henderiw/logger v0.0.0-20230911123436-8655829b1abe
github.com/henderiw/store v0.0.2-0.20241020093537-5a92d3e14a02
github.com/henderiw/store v0.0.2-0.20241030044529-f6baff74eab3
github.com/kform-dev/kform v0.0.16-0.20241029050934-f462791a4045
github.com/kuidio/kuid v0.0.8-0.20241029083905-509e46e5a98a
github.com/kuidio/kuid v0.0.8-0.20241030070053-17bc7b6f6501
github.com/pkg/errors v0.9.1
github.com/rivo/tview v0.0.0-20240818110301-fd649dbf1223
github.com/spf13/cobra v1.8.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ github.com/henderiw/iputil v0.0.0-20231218081610-37f78ad9c81c h1:nFnCNyRV1Ej/zqV
github.com/henderiw/iputil v0.0.0-20231218081610-37f78ad9c81c/go.mod h1:PrPJdVAwtl5tL323wykHZ5L/b7tfJJsjhegza/wq4fQ=
github.com/henderiw/logger v0.0.0-20230911123436-8655829b1abe h1:+R53KH7fW+pmqlfSYVTCGPn8pj6gqBGcQ0nq7L1h8+g=
github.com/henderiw/logger v0.0.0-20230911123436-8655829b1abe/go.mod h1:KNMXpSG8v0BAfIh5rZL4hgow3pBWNbkmmb28x9C5s+Y=
github.com/henderiw/store v0.0.2-0.20241030044529-f6baff74eab3 h1:/akPyTNVwB58j5vf0HPqTgsaTmeRGO2v5pnC2dHXJhk=
github.com/henderiw/store v0.0.2-0.20241030044529-f6baff74eab3/go.mod h1:BS0axsmGORgxlBKcdl9T+oxhWEyTwSpb4ZyIqulQ2Bc=
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
Expand Down Expand Up @@ -229,6 +231,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kuidio/kuid v0.0.8-0.20241030070053-17bc7b6f6501 h1:05owRsdwoKjdLVlGpZFtlUGNyOsvgPfW/OgvlPd7L1s=
github.com/kuidio/kuid v0.0.8-0.20241030070053-17bc7b6f6501/go.mod h1:wi+BSP3HgYqzs/6uRCCO8RNJzMviG4VoIHpcdR88K/s=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
Expand Down
12 changes: 6 additions & 6 deletions pkg/controller/reconciler/gotemplate/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (r *reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco
r.resources = resources.New(r.name, r.client, u, r.owns, r.branch)
if u.GetDeletionTimestamp() != nil {
if err := r.resources.Delete(ctx); err != nil {
return reconcile.Result{}, fmt.Errorf("go template %s cannot delete child resource, err: %s", r.name, err.Error())
return reconcile.Result{}, fmt.Errorf("gotemplate reconciler %s cannot delete child resource, err: %s", r.name, err.Error())
}
object.DeleteFinalizer(u, r.name)

Expand All @@ -101,7 +101,7 @@ func (r *reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco
FieldManager: r.name,
Branch: r.branch,
}); err != nil {
return reconcile.Result{}, fmt.Errorf("go template %s cannot set finalizer, err: %s", r.name, err.Error())
return reconcile.Result{}, fmt.Errorf("gotemplate reconciler %s cannot set finalizer, err: %s", r.name, err.Error())
}
return reconcile.Result{}, nil
}
Expand All @@ -110,20 +110,20 @@ func (r *reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco

var buf bytes.Buffer
if err := r.parser.Render(ctx, "main.tpl", u, &buf); err != nil {
return reconcile.Result{}, fmt.Errorf("go template %s parser failed err: %s", r.name, err.Error())
return reconcile.Result{}, fmt.Errorf("gotemplate reconciler %s parser failed err: %s", r.name, err.Error())
}

data := map[string]any{}
if err := yaml.Unmarshal(buf.Bytes(), &data); err != nil {
return reconcile.Result{}, fmt.Errorf("go template %s generate invalid yaml failed err: %s", r.name, err.Error())
return reconcile.Result{}, fmt.Errorf("gotemplate reconciler %s generate invalid yaml failed err: %s", r.name, err.Error())
}

// apply the own resource generated by the template
newu := &unstructured.Unstructured{}
newu.Object = data
r.resources.AddNewResource(ctx, newu)
if err := r.resources.Apply(ctx); err != nil {
return reconcile.Result{}, fmt.Errorf("apply failed for gotemplate %s, err: %s", r.name, err.Error())
return reconcile.Result{}, fmt.Errorf("apply failed for gotemplate reconciler %s, err: %s", r.name, err.Error())
}

// removes the fields that are not managed by this reconciler based on the managedFields info in the resource
Expand All @@ -134,7 +134,7 @@ func (r *reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco
FieldManager: r.name,
Branch: r.branch,
}); err != nil {
return reconcile.Result{}, fmt.Errorf("go template %s cannot set finalizer, err: %s", r.name, err.Error())
return reconcile.Result{}, fmt.Errorf("go template reconciler %s cannot set finalizer, err: %s", r.name, err.Error())
}
return reconcile.Result{}, nil
}
Loading

0 comments on commit 1e92e14

Please sign in to comment.