@@ -9,20 +9,17 @@ import (
99 "context"
1010 "fmt"
1111 "runtime"
12- "time"
1312
1413 apv1beta2 "github.com/k0sproject/k0s/pkg/apis/autopilot/v1beta2"
1514 apcli "github.com/k0sproject/k0s/pkg/autopilot/client"
1615 apcomm "github.com/k0sproject/k0s/pkg/autopilot/common"
1716 apconst "github.com/k0sproject/k0s/pkg/autopilot/constant"
1817 "github.com/k0sproject/k0s/pkg/build"
1918 "github.com/k0sproject/k0s/pkg/component/status"
20- "github.com/k0sproject/k0s/pkg/kubernetes/watch"
2119
2220 "github.com/avast/retry-go"
2321 "github.com/sirupsen/logrus"
2422 corev1 "k8s.io/api/core/v1"
25- extensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2623 "k8s.io/apimachinery/pkg/api/errors"
2724 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2825)
@@ -81,7 +78,7 @@ func (sc *setupController) Run(ctx context.Context) error {
8178
8279 if err := retry .Do (func () error {
8380 logger .Infof ("Attempting to create controlnode '%s'" , controlNodeName )
84- if err := sc .createControlNode (ctx , sc . clientFactory , controlNodeName , kubeletNodeName ); err != nil {
81+ if err := sc .createControlNode (ctx , controlNodeName , kubeletNodeName ); err != nil {
8582 return fmt .Errorf ("create controlnode '%s' attempt failed, retrying: %w" , controlNodeName , err )
8683 }
8784
@@ -112,7 +109,7 @@ func createNamespace(ctx context.Context, cf apcli.FactoryInterface, name string
112109
113110// createControlNode creates a new control node, ignoring errors if one already exists
114111// for this physical host.
115- func (sc * setupController ) createControlNode (ctx context.Context , cf apcli. FactoryInterface , name , nodeName string ) error {
112+ func (sc * setupController ) createControlNode (ctx context.Context , name , nodeName string ) error {
116113 logger := sc .log .WithField ("component" , "setup" )
117114 client , err := sc .clientFactory .GetK0sClient ()
118115 if err != nil {
@@ -122,13 +119,6 @@ func (sc *setupController) createControlNode(ctx context.Context, cf apcli.Facto
122119 // Create the ControlNode object if needed
123120 node , err := client .AutopilotV1beta2 ().ControlNodes ().Get (ctx , name , metav1.GetOptions {})
124121 if errors .IsNotFound (err ) {
125- logger .Info ("Autopilot 'controlnodes' CRD not found, waiting..." )
126- if err := sc .waitForControlNodesCRD (ctx , cf ); err != nil {
127- return fmt .Errorf ("while waiting for autopilot 'controlnodes' CRD: %w" , err )
128- }
129-
130- logger .Info ("Autopilot 'controlnodes' CRD found, continuing" )
131-
132122 logger .Infof ("ControlNode '%s' not found, creating" , name )
133123 mode := apconst .K0SControlNodeModeController
134124 if sc .enableWorker {
@@ -208,36 +198,3 @@ func getControllerAPIAddress() (string, error) {
208198
209199 return status .ClusterConfig .Spec .API .Address , nil
210200}
211-
212- // waitForControlNodesCRD waits until the controlnodes CRD is established for
213- // max 2 minutes.
214- func (sc * setupController ) waitForControlNodesCRD (ctx context.Context , cf apcli.FactoryInterface ) error {
215- extClient , err := cf .GetExtensionClient ()
216- if err != nil {
217- return fmt .Errorf ("unable to obtain extensions client: %w" , err )
218- }
219-
220- ctx , cancel := context .WithTimeout (ctx , 2 * time .Minute )
221- defer cancel ()
222- return watch .CRDs (extClient .CustomResourceDefinitions ()).
223- WithObjectName ("controlnodes." + apv1beta2 .GroupName ).
224- WithErrorCallback (func (err error ) (time.Duration , error ) {
225- if retryDelay , e := watch .IsRetryable (err ); e == nil {
226- sc .log .WithError (err ).Debugf (
227- "Encountered transient error while waiting for autopilot 'controlnodes' CRD, retrying in %s" ,
228- retryDelay ,
229- )
230- return retryDelay , nil
231- }
232- return 0 , err
233- }).
234- Until (ctx , func (item * extensionsv1.CustomResourceDefinition ) (bool , error ) {
235- for _ , cond := range item .Status .Conditions {
236- if cond .Type == extensionsv1 .Established {
237- return cond .Status == extensionsv1 .ConditionTrue , nil
238- }
239- }
240-
241- return false , nil
242- })
243- }
0 commit comments