|
| 1 | +const nodeCloud = require("../../lib/"); |
| 2 | +const optionsProvider = { |
| 3 | + overrideProviders: false |
| 4 | +}; |
| 5 | +const ncProviders = nodeCloud.getProviders(optionsProvider); |
| 6 | +const options = { |
| 7 | + apiVersion: "2017-11-01" |
| 8 | +}; |
| 9 | + |
| 10 | +const kubernetesModule = ncProviders.aws.kubernetes(options); |
| 11 | + |
| 12 | +function createCluster() { |
| 13 | + const clusterDetails = { |
| 14 | + version: "1.15", |
| 15 | + name: "NodeCloud", |
| 16 | + clientRequestToken: "1d2129a1-3d38-460a-9756-e5b91fddb951", |
| 17 | + resourcesVpcConfig: { |
| 18 | + securityGroupIds: ["sg-5af38400"], |
| 19 | + subnetIds: ["subnet-13c32f5e", "subnet-42633a1e"] |
| 20 | + }, |
| 21 | + roleArn: "arn:aws:iam::686610322591:role/eksClusterRoleNodeCloud" |
| 22 | + }; |
| 23 | + |
| 24 | + kubernetesModule.create(clusterDetails).then( |
| 25 | + result => { |
| 26 | + console.log("Output :", result); |
| 27 | + }, |
| 28 | + error => { |
| 29 | + console.error("Error :", error); |
| 30 | + } |
| 31 | + ); |
| 32 | +} |
| 33 | + |
| 34 | +function getClusterDetails() { |
| 35 | + const params = { |
| 36 | + name: "NodeCloud" |
| 37 | + }; |
| 38 | + |
| 39 | + kubernetesModule.describeCluster(params).then( |
| 40 | + result => { |
| 41 | + console.log("Output :", result); |
| 42 | + }, |
| 43 | + error => { |
| 44 | + console.error("Error :", error); |
| 45 | + } |
| 46 | + ); |
| 47 | +} |
| 48 | + |
| 49 | +function getAllClusters() { |
| 50 | + /* The nextToken value returned from a previous ListClusters request where maxResults was used and the results |
| 51 | + exceeded the value of that parameter. Pagination continues from the end of the previous results that returned the |
| 52 | + nextToken value. The maximum number of clusters you can get through this request is 100, use the nextToken parameter |
| 53 | + to get the rest clusters using a another request*/ |
| 54 | + const limitation = { |
| 55 | + maxResults: 20 |
| 56 | + // nextToken: 'STRING_VALUE' -- optional |
| 57 | + }; |
| 58 | + |
| 59 | + // Limitation can be a empty empty object as well, where it will give 100 clusters max |
| 60 | + |
| 61 | + kubernetesModule.listClusters(limitation).then( |
| 62 | + result => { |
| 63 | + console.log("Output :", result); |
| 64 | + }, |
| 65 | + error => { |
| 66 | + console.error("Error :", error); |
| 67 | + } |
| 68 | + ); |
| 69 | +} |
| 70 | + |
| 71 | +function getClusterUpdates() { |
| 72 | + const requestData = { |
| 73 | + name: "NodeCloud", // required |
| 74 | + maxResults: "10" |
| 75 | + // nextToken: 'STRING_VALUE', -- optional |
| 76 | + // nodegroupName: 'STRING_VALUE' -- optional |
| 77 | + }; |
| 78 | + |
| 79 | + kubernetesModule.listUpdates(requestData).then( |
| 80 | + result => { |
| 81 | + console.log("Output :", result); |
| 82 | + }, |
| 83 | + error => { |
| 84 | + console.error("Error :", error); |
| 85 | + } |
| 86 | + ); |
| 87 | +} |
| 88 | + |
| 89 | +function updateVersion() { |
| 90 | + // When creating the cluster the version was 1.15 and now upgrading to 1.16 |
| 91 | + const clusterDetails = { |
| 92 | + name: "NodeCloud", // required |
| 93 | + version: "1.16" // required |
| 94 | + // clientRequestToken: 'STRING_VALUE' -- optional |
| 95 | + }; |
| 96 | + |
| 97 | + kubernetesModule.updateClusterVersion(clusterDetails).then( |
| 98 | + result => { |
| 99 | + console.log("Output :", result); |
| 100 | + }, |
| 101 | + error => { |
| 102 | + console.error("Error :", error); |
| 103 | + } |
| 104 | + ); |
| 105 | +} |
| 106 | + |
| 107 | +function updateConfiguration() { |
| 108 | + const configData = { |
| 109 | + name: "NodeCloud", // required |
| 110 | + // clientRequestToken: 'STRING_VALUE', -- optional |
| 111 | + logging: { |
| 112 | + clusterLogging: [ |
| 113 | + { |
| 114 | + enabled: true, |
| 115 | + types: ["api"] |
| 116 | + } |
| 117 | + ] |
| 118 | + } |
| 119 | + }; |
| 120 | + |
| 121 | + kubernetesModule.updateClusterConfig(configData).then( |
| 122 | + result => { |
| 123 | + console.log("Output :", result); |
| 124 | + }, |
| 125 | + error => { |
| 126 | + console.error("Error :", error); |
| 127 | + } |
| 128 | + ); |
| 129 | +} |
| 130 | + |
| 131 | +function createNodeGroup() { |
| 132 | + const groupDeatils = { |
| 133 | + clusterName: "NodeCloud", |
| 134 | + nodeRole: "arn:aws:iam::686610322591:role/NodeCloudInstanceRole", |
| 135 | + nodegroupName: "groupTest", |
| 136 | + subnets: ["subnet-13c32f5e", "subnet-42633a1e"], |
| 137 | + amiType: "AL2_x86_64", |
| 138 | + version: "1.16" |
| 139 | + }; |
| 140 | + |
| 141 | + kubernetesModule.createNodeGroup(groupDeatils).then( |
| 142 | + result => { |
| 143 | + console.log("Output :", result); |
| 144 | + }, |
| 145 | + error => { |
| 146 | + console.error("Error :", error); |
| 147 | + } |
| 148 | + ); |
| 149 | +} |
| 150 | + |
| 151 | +function createFargateProfile() { |
| 152 | + var profileData = { |
| 153 | + clusterName: "NodeCloud", // required |
| 154 | + fargateProfileName: "fargateTest", // required |
| 155 | + podExecutionRoleArn: "arn:aws:iam::686610322591:role/nodelCloudfargate", // required |
| 156 | + // clientRequestToken: 'STRING_VALUE', -- optional |
| 157 | + selectors: [ |
| 158 | + { |
| 159 | + labels: { |
| 160 | + selector: "nodeCloudTest" |
| 161 | + }, |
| 162 | + namespace: "nc" |
| 163 | + } |
| 164 | + ], |
| 165 | + subnets: ["subnet-d8702bf6"] |
| 166 | + }; |
| 167 | + |
| 168 | + kubernetesModule.createFargateProfile(profileData).then( |
| 169 | + result => { |
| 170 | + console.log("Output :", result); |
| 171 | + }, |
| 172 | + error => { |
| 173 | + console.error("Error :", error); |
| 174 | + } |
| 175 | + ); |
| 176 | +} |
| 177 | + |
| 178 | +function getFargateProfileInfo() { |
| 179 | + const requestData = { |
| 180 | + clusterName: "NodeCloud", |
| 181 | + fargateProfileName: "fargateTest" |
| 182 | + }; |
| 183 | + |
| 184 | + kubernetesModule.describeFargateProfile(requestData).then( |
| 185 | + result => { |
| 186 | + console.log("Output :", result); |
| 187 | + }, |
| 188 | + error => { |
| 189 | + console.error("Error :", error); |
| 190 | + } |
| 191 | + ); |
| 192 | +} |
| 193 | + |
| 194 | +function deleteFargateProfile() { |
| 195 | + const fargateProfileDetails = { |
| 196 | + clusterName: "NodeCloud", |
| 197 | + fargateProfileName: "fargateTest" |
| 198 | + }; |
| 199 | + |
| 200 | + kubernetesModule.deleteFargateProfile(fargateProfileDetails).then( |
| 201 | + result => { |
| 202 | + console.log("Output :", result); |
| 203 | + }, |
| 204 | + error => { |
| 205 | + console.error("Error :", error); |
| 206 | + } |
| 207 | + ); |
| 208 | +} |
| 209 | + |
| 210 | +function deleteNodeGroup() { |
| 211 | + const nodeGroupDetails = { |
| 212 | + clusterName: "NodeCloud", |
| 213 | + nodegroupName: "groupTest" |
| 214 | + }; |
| 215 | + |
| 216 | + kubernetesModule.deleteNodegroup(nodeGroupDetails).then( |
| 217 | + result => { |
| 218 | + console.log("Output :", result); |
| 219 | + }, |
| 220 | + error => { |
| 221 | + console.error("Error :", error); |
| 222 | + } |
| 223 | + ); |
| 224 | +} |
| 225 | + |
| 226 | +function deleteCluster() { |
| 227 | + const clusterDetails = { |
| 228 | + name: "NodeCloud" |
| 229 | + }; |
| 230 | + |
| 231 | + kubernetesModule.deleteCluster(clusterDetails).then( |
| 232 | + result => { |
| 233 | + console.log("Output :", result); |
| 234 | + }, |
| 235 | + error => { |
| 236 | + console.error("Error :", error); |
| 237 | + } |
| 238 | + ); |
| 239 | +} |
0 commit comments