@@ -20,6 +20,7 @@ import (
2020 "context"
2121
2222 "github.com/awslabs/operatorpkg/reasonable"
23+ "go.uber.org/multierr"
2324 "k8s.io/apimachinery/pkg/api/equality"
2425 "k8s.io/apimachinery/pkg/api/errors"
2526 controllerruntime "sigs.k8s.io/controller-runtime"
@@ -29,17 +30,30 @@ import (
2930 "sigs.k8s.io/controller-runtime/pkg/manager"
3031 "sigs.k8s.io/controller-runtime/pkg/reconcile"
3132 "sigs.k8s.io/karpenter/pkg/operator/injection"
33+ "sigs.k8s.io/karpenter/pkg/utils/result"
3234
3335 "github.com/cloudpilot-ai/karpenter-provider-alicloud/pkg/apis/v1alpha1"
36+ "github.com/cloudpilot-ai/karpenter-provider-alicloud/pkg/providers/securitygroup"
37+ "github.com/cloudpilot-ai/karpenter-provider-alicloud/pkg/providers/vswitch"
3438)
3539
40+ type nodeClassStatusReconciler interface {
41+ Reconcile (context.Context , * v1alpha1.ECSNodeClass ) (reconcile.Result , error )
42+ }
43+
3644type Controller struct {
3745 kubeClient client.Client
46+
47+ vSwitch * VSwitch
48+ securitygroup * SecurityGroup
3849}
3950
40- func NewController (kubeClient client.Client ) * Controller {
51+ func NewController (kubeClient client.Client , vSwitchProvider vswitch. Provider , securitygroupProvider securitygroup. Provider ) * Controller {
4152 return & Controller {
4253 kubeClient : kubeClient ,
54+
55+ vSwitch : & VSwitch {vSwitchProvider : vSwitchProvider },
56+ securitygroup : & SecurityGroup {securityGroupProvider : securitygroupProvider },
4357 }
4458}
4559
@@ -64,8 +78,17 @@ func (c *Controller) Reconcile(ctx context.Context, nodeClass *v1alpha1.ECSNodeC
6478
6579 // TODO: implement different conditions setup
6680 nodeClass .StatusConditions ().SetTrue (v1alpha1 .ConditionTypeInstanceRAMReady )
67- nodeClass .StatusConditions ().SetTrue (v1alpha1 .ConditionTypeSecurityGroupsReady )
68- nodeClass .StatusConditions ().SetTrue (v1alpha1 .ConditionTypeVSwitchsReady )
81+
82+ var results []reconcile.Result
83+ var errs error
84+ for _ , reconciler := range []nodeClassStatusReconciler {
85+ c .vSwitch ,
86+ c .securitygroup ,
87+ } {
88+ res , err := reconciler .Reconcile (ctx , nodeClass )
89+ errs = multierr .Append (errs , err )
90+ results = append (results , res )
91+ }
6992
7093 if ! equality .Semantic .DeepEqual (stored , nodeClass ) {
7194 // We use client.MergeFromWithOptimisticLock because patching a list with a JSON merge patch
@@ -75,11 +98,14 @@ func (c *Controller) Reconcile(ctx context.Context, nodeClass *v1alpha1.ECSNodeC
7598 if errors .IsConflict (err ) {
7699 return reconcile.Result {Requeue : true }, nil
77100 }
78- return reconcile. Result {} , client .IgnoreNotFound (err )
101+ errs = multierr . Append ( errs , client .IgnoreNotFound (err ) )
79102 }
80103 }
81104
82- return reconcile.Result {}, nil
105+ if errs != nil {
106+ return reconcile.Result {}, errs
107+ }
108+ return result .Min (results ... ), nil
83109}
84110
85111func (c * Controller ) Register (_ context.Context , m manager.Manager ) error {
0 commit comments