Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Tye deploy doesn't respect namespace when checking kubectl cluster-info #1544

Open
RSoeborg opened this issue Feb 23, 2023 · 1 comment
Open
Labels
bug Something isn't working

Comments

@RSoeborg
Copy link

Describe the bug

Some kubernetes providers doesn't allow you to access the "kube system". This is a problem when deploying, since the KubectlDetector class calls kubectl cluster-info.

No matter what namespace is defined for your current context, kubectl cluster-info always tries to retrieve from kube-system unless you directly specify kubectl cluster-info --namespace=my-namespace

The issue is that even if I try to deploy with tye deploy --namespace my-namespace it doesn't use that namespace when it checks if kubectl is connected to a cluster in IsKubectlConnectedToClusterAsync() - so in return I get a Forbidden error back, and since it has a non zero exit code, Tye says that kubectl is not connected to a cluster (even though it is).

Further technical details

  • Include the output of tye --version
    0.11.0-alpha.22111.1+3edef5428949c518c078844d6438e5ba86fce600

  • If possible rerun the command with -v debug and include the output

$ tye deploy -v debug --namespace rsoeborg
Loading Application Details...
Restoring and evaluating projects
Resolved metadata for service site-crawler at /home/rso/repos/SDT/services/site.crawler/obj/Debug/net6.0/MicrosoftTye.ProjectMetadata.txt
Resolved metadata for service test-service at /home/rso/repos/SDT/services/test.service/obj/Debug/net6.0/MicrosoftTye.ProjectMetadata.txt
Resolved metadata for service auth-service at /home/rso/repos/SDT/services/auth.service/obj/Debug/net6.0/MicrosoftTye.ProjectMetadata.txt
Restore and project evaluation took: 1891.2194ms
Found application version: 1.0.0
RunCommand=/home/rso/repos/SDT/services/site.crawler/bin/Debug/net6.0/site.crawler
RunArguments=
TargetPath=/home/rso/repos/SDT/services/site.crawler/bin/Debug/net6.0/site.crawler.dll
PublishDir=bin/Debug/net6.0/publish/
AssemblyName=site.crawler
IntermediateOutputPath=obj/Debug/net6.0/
Found target framework: net6.0
Parsed target framework name: net
Parsed target framework version: 6.0
Found shared frameworks: Microsoft.NETCore.App, Microsoft.AspNetCore.App
IsAspNet=True
Evaluation Took: 2.6088ms
Found application version: 1.0.0
RunCommand=/home/rso/repos/SDT/services/test.service/bin/Debug/net6.0/test.service
RunArguments=
TargetPath=/home/rso/repos/SDT/services/test.service/bin/Debug/net6.0/test.service.dll
PublishDir=bin/Debug/net6.0/publish/
AssemblyName=test.service
IntermediateOutputPath=obj/Debug/net6.0/
Found target framework: net6.0
Parsed target framework name: net
Parsed target framework version: 6.0
Found shared frameworks: Microsoft.NETCore.App, Microsoft.AspNetCore.App
IsAspNet=True
Evaluation Took: 1.0948ms
Found application version: 1.0.0
RunCommand=/home/rso/repos/SDT/services/auth.service/bin/Debug/net6.0/auth.service
RunArguments=
TargetPath=/home/rso/repos/SDT/services/auth.service/bin/Debug/net6.0/auth.service.dll
PublishDir=bin/Debug/net6.0/publish/
AssemblyName=auth.service
IntermediateOutputPath=obj/Debug/net6.0/
Found target framework: net6.0
Parsed target framework name: net
Parsed target framework version: 6.0
Found shared frameworks: Microsoft.NETCore.App, Microsoft.AspNetCore.App
IsAspNet=True
Evaluation Took: 0.2791ms
Verifying kubectl installation...
Verifying kubectl connection to cluster...
Drats! 'deploy' failed:
        Cannot apply manifests because kubectl is not connected to a cluster.
  • The platform (Linux/macOS/Windows)

Linux running on WSL: cat /etc/os-release

NAME="Ubuntu"
VERSION="20.04 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
@RSoeborg RSoeborg added the bug Something isn't working label Feb 23, 2023
@RSoeborg
Copy link
Author

RSoeborg commented Feb 23, 2023

Just to add to this issue:

In the ingress validation step, the namespace is set but not used when listing deployments: ListDeploymentForAllNamespacesWithHttpMessagesAsync, giving a 403 Forbidden as well

            // If namespace is null, set it to default
            config.Namespace ??= "default";

            var kubernetes = new Kubernetes(config);

            // Looking for a deployment using a standard label.
            // Note: using a deployment instead of a service - minikube doesn't create a service for the controller.

            try
            {
                var result = await kubernetes.ListDeploymentForAllNamespacesWithHttpMessagesAsync(
                    labelSelector: "app.kubernetes.io/name in (ingress-nginx, nginx-ingress-controller)");
                if (result.Body.Items.Count > 0)
                {
                    foreach (var service in result.Body.Items)
                    {
                        output.WriteInfoLine($"Found existing ingress controller '{service.Metadata.Name}' in namespace '{service.Metadata.NamespaceProperty}'.");
                    }

                    return;
                }
            }

And even with "--Force", the fetch step still occurs and fails (due to the 403) - The Force guard should perhaps be in the top of the file?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant