in operator/pkg/controllers/addons/addons.go [67:95]
func (c *Controller) createKubeClient(ctx context.Context, nn types.NamespacedName) (*kubeprovider.Client, error) {
// Get the admin kube config stored in a secret in the management cluster
adminSecret, err := keypairs.Reconciler(c.substrateClient).GetSecretFromServer(ctx, object.NamespacedName(
master.KubeAdminSecretNameFor(nn.Name), nn.Namespace))
if err != nil {
return nil, err
}
restConfig, err := clientcmd.RESTConfigFromKubeConfig(adminSecret.Data[secrets.SecretConfigKey])
if err != nil {
return nil, fmt.Errorf("creating rest config for new cluster, %w", err)
}
newClient, err := client.New(restConfig, client.Options{Scheme: scheme.GuestCluster})
if err != nil {
if errors.IsDNSLookUpNoSuchHost(err) {
return nil, fmt.Errorf("%v control plane endpoint not ready, lookup failed, %w", nn.Name, errors.WaitingForSubResources)
}
if errors.IsNetIOTimeOut(err) {
// This happens 1-2 times, but if it happens more we would want to know in the logs
zap.S().Errorf("Creating kubeclient, net i/o timed out for control plane %s endpoint", nn.Name)
return nil, fmt.Errorf("net i/o timeout for %v control plane endpoint, %w", nn.Name, errors.WaitingForSubResources)
}
if errors.IsConnectionRefused(err) {
zap.S().Errorf("Creating kubeclient, connection refused for control plane %s endpoint", nn.Name)
return nil, fmt.Errorf("connection refused %v control plane endpoint, %w", nn.Name, errors.WaitingForSubResources)
}
return nil, fmt.Errorf("creating kubeclient for new cluster, %w", err)
}
return kubeprovider.New(newClient), nil
}