func()

in pkg/authenticator/target_cluster_client.go [196:224]


func (tcc *targetClusterClient) CheckNamespace(ctx context.Context, namespace string) bool {
	if tcc.clientConfig == nil {
		tcc.logger.Error(fmt.Errorf("client is not initialized"), "checking namespace", "namespace", "namespace")
		return false
	}

	restConfig, err := tcc.ToRESTConfig()
	if err != nil {
		tcc.logger.V(6).Error(err, "creating rest config", "namespace", namespace)
		return false
	}

	k8sClient, err := client.New(restConfig, client.Options{})
	if err != nil {
		tcc.logger.V(6).Error(err, "creating k8s client", "namespace", namespace)
		return false
	}

	nn := types.NamespacedName{Name: namespace}
	ns := &corev1.Namespace{}
	if err := k8sClient.Get(ctx, nn, ns); err != nil {
		if !apierrors.IsNotFound(err) {
			tcc.logger.V(6).Error(err, "getting namespace", "namespace", namespace)
		}
		return false
	}

	return true
}