Giter VIP home page Giter VIP logo

Comments (4)

lukehoban avatar lukehoban commented on June 27, 2024

Definitely would make sense to expose it as a public API here - but note that you can construct it from aws.eks.Cluster.get() using this code from the implementation of the library:

function generateKubeconfig(
clusterName: pulumi.Input<string>,
clusterEndpoint: pulumi.Input<string>,
certData: pulumi.Input<string>,
opts?: KubeconfigOptions) {
let args = ["eks", "get-token", "--cluster-name", clusterName];
let env: ExecEnvVar[] | undefined;
if (opts?.roleArn) {
args = [...args, "--role", opts.roleArn];
}
if (opts?.profileName) {
env = [{
"name": "AWS_PROFILE",
"value": opts.profileName,
}];
}
return pulumi.all([
args,
env,
]).apply(([tokenArgs, envvars]) => ({
apiVersion: "v1",
clusters: [{
cluster: {
server: clusterEndpoint,
"certificate-authority-data": certData,
},
name: "kubernetes",
}],
contexts: [{
context: {
cluster: "kubernetes",
user: "aws",
},
name: "aws",
}],
"current-context": "aws",
kind: "Config",
users: [{
name: "aws",
user: {
exec: {
apiVersion: "client.authentication.k8s.io/v1alpha1",
command: "aws",
args: tokenArgs,
env: envvars,
},
},
}],
}));
}

from pulumi-eks.

RobCannon avatar RobCannon commented on June 27, 2024

I was very disappointed to find that the object returned by getCluster does not have a kubeconfig or Kubernetes provider.

I wanted to move the code that installs stuff into the cluster into a different project from the project that creates the cluster. The project was getting way too big and the dependency handling was a problem, especially when trying to destroy and rebuild a cluster.

I tried using the source code for generateKubeConfig, copied into my pulumi project with this source code, but it still does not work:

const cluster = aws.eks.getClusterOutput({ name: config.accountName });

const kubeconfig = generateKubeconfig(cluster.name, cluster.endpoint, cluster.certificateAuthorities[0].data);

const kubernetesProvider = new kubernetes.Provider('kubernetes-provider', {
  kubeconfig: kubeconfig.apply(JSON.stringify),
});

const argoCdCrds = new kubernetes.kustomize.Directory(
  'argo-cd-crds',
  {
    directory: `https://github.com/argoproj/argo-cd/tree/${argoCdApplicationVersion}/manifests/crds`,
    resourcePrefix: 'argo-cd-crds',
  },
  {
    provider: kubernetesProvider,
  }
);

I know the connection to AWS is good, because getClusterOutput returns valid endpoints and certs. I can look at the value for kubconfig in an exported state.json file, and they are IDENTICAL to the values in my pulumi project that creates the cluster, where this code ran before.

But, I get this error:

 kubernetes:apiextensions.k8s.io/v1:CustomResourceDefinition (argo-cd-crds-appprojects.argoproj.io):
      warning: configured Kubernetes cluster is unreachable: unable to load schema information from the API server: the server has asked for the client to provide credentials
      error: failed to read resource state due to unreachable cluster. If the cluster was deleted, you can remove this resource from Pulumi state by rerunning the operation with the PULUMI_K8S_DELETE_UNREACHABLE environment variable set to "true"

Does anyone know what I might be missing?

from pulumi-eks.

bithavoc avatar bithavoc commented on June 27, 2024

@RobCannon did you find a solution? they recommend importing the cluster, but that fails too:

const currentProvider = new aws.Provider("current", {
  region: awsConfig.require('region') as aws.Region,
  accessKey: awsConfig.require('accessKey'),
  secretKey: awsConfig.requireSecret('secretKey'),
});

const cluster = new eks.Cluster("cluster", {

  }, {
    id: "eu-west-3",
    provider: currentProvider,
  });
 error: ResourceError: Cannot read an existing resource unless it has a custom provider

from pulumi-eks.

steveteuber avatar steveteuber commented on June 27, 2024

My current workaround looks like this:

const cluster = aws.eks.getCluster({
  name: "hpi-eks-prod",
});

const kubeconfig = pulumi.output(cluster).apply(cluster => ({
  apiVersion: "v1",
  kind: "Config",
  "current-context": "aws",
  clusters: [{
    name: "kubernetes",
    cluster: {
      server: cluster.endpoint,
      "certificate-authority-data": cluster.certificateAuthorities[0].data,
    },
  }],
  users: [{
    name: "aws",
    user: {
      exec: {
        apiVersion: "client.authentication.k8s.io/v1beta1",
        command: "aws",
        args: ["eks", "get-token", "--cluster-name", cluster.name],
      },
    },
  }],
  contexts: [{
    name: "aws",
    context: {
      cluster: "kubernetes",
      user: "aws",
    },
  }],
}));

const provider = new k8s.Provider("default", {
  kubeconfig: kubeconfig.apply(JSON.stringify),
});

from pulumi-eks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.