public static async Task MainContainerEngineNodePool() { logger.Info("Starting example"); string compartmentId = Environment.GetEnvironmentVariable("OCI_COMPARTMENT_ID"); var provider = new ConfigFileAuthenticationDetailsProvider(OciConfigProfileName); var containerEngineClient = new ContainerEngineClient(provider); var vcnClient = new VirtualNetworkClient(provider); var identityClient = new IdentityClient(provider); Vcn vcn = null; List <Subnet> subnets = null; List <string> lbSubnetIds = new List <string>(); List <string> poolSubnetIds = new List <string>(); Cluster cluster = null; NodePool nodePool = null; try { List <IdentityModels.AvailabilityDomain> availablityDomains = await GetAvailabilityDomains(identityClient, compartmentId); vcn = await CreateVcn(vcnClient, compartmentId); subnets = await CreateSubnets(vcnClient, compartmentId, vcn); lbSubnetIds.Add(subnets[0].Id); poolSubnetIds.Add(subnets[1].Id); var kubernetesVersion = await GetKubernetesVersion(containerEngineClient); cluster = await CreateCluster(containerEngineClient, vcn.Id, lbSubnetIds, kubernetesVersion, compartmentId); // Add node pool in the cluster KeyValue keyValue = new KeyValue { Key = "key1", Value = "value1" }; List <KeyValue> initialNodeLabels = new List <KeyValue> { keyValue }; List <NodePoolPlacementConfigDetails> nodePoolPlacementConfigDetails = new List <NodePoolPlacementConfigDetails>(); foreach (var availabilityDomain in availablityDomains) { nodePoolPlacementConfigDetails.Add(new NodePoolPlacementConfigDetails { AvailabilityDomain = availabilityDomain.Name, SubnetId = poolSubnetIds[0] }); } ; var createNodePoolNodeConfigDetails = new CreateNodePoolNodeConfigDetails { Size = availablityDomains.Count, PlacementConfigs = nodePoolPlacementConfigDetails }; nodePool = await CreateNodePool(containerEngineClient, compartmentId, cluster.Id, NodePoolDisplayName, kubernetesVersion, NodeImageName, NodeShape, initialNodeLabels, createNodePoolNodeConfigDetails); logger.Info("Created node pool"); // Update the node pool await UpdateNodePool(containerEngineClient, nodePool.Id, NewNodePoolDisplayName); } catch (Exception e) { logger.Error($"Failed to create container engine cluster: {e}"); } finally { logger.Info("Cleaning up..."); if (nodePool != null) { await DeleteNodePool(containerEngineClient, nodePool.Id); } if (cluster != null) { await DeleteCluster(containerEngineClient, cluster.Id); } for (int i = 0; i < 2; i++) { if (subnets[i] != null) { await DeleteSubnet(vcnClient, subnets[i]); } } if (vcn != null) { await DeleteVcn(vcnClient, vcn); } containerEngineClient.Dispose(); vcnClient.Dispose(); identityClient.Dispose(); } logger.Info("End example"); }
/** * Creates a node pool in a cluster and waits until the work request finished * * @param containerEngineClient the containerEngineclient used to create the node pool * @param compartmentId The compartment ID * @param clusterId The ID of the cluster that the node pool is added in * @param displayName The display name of the node pool * @param kubernetesVersion kubernetesVersion * @param nodeImageName The image to use on each node in the node pool * @param nodeShape The number of CPUs and the amount of memory allocated to each node in the node pool * @param initialNodeLabels The initial node label * @param nodePoolNodeConfigDetails The node pool size and the placementConfig of nodes. * @return the created node pool */ private static async Task <NodePool> CreateNodePool(ContainerEngineClient containerEngineClient, string compartmentId, string clusterId, string displayName, string kubernetesVersion, string nodeImageName, string nodeShape, List <KeyValue> initialNodeLabels, CreateNodePoolNodeConfigDetails nodePoolNodeConfigDetails) { var createNodePoolDetails = new CreateNodePoolDetails { CompartmentId = compartmentId, ClusterId = clusterId, Name = displayName, KubernetesVersion = kubernetesVersion, NodeImageName = nodeImageName, InitialNodeLabels = initialNodeLabels, NodeConfigDetails = nodePoolNodeConfigDetails, NodeShape = nodeShape }; var createNodePoolRequest = new CreateNodePoolRequest { CreateNodePoolDetails = createNodePoolDetails }; var createNodePoolResponse = await containerEngineClient.CreateNodePool(createNodePoolRequest); string workRequestId = createNodePoolResponse.OpcWorkRequestId; logger.Info($"Create node pool work request ID: {workRequestId}"); GetWorkRequestResponse workRequestResponse = WaitForWorkRequestFinished(containerEngineClient, workRequestId); var nodePoolId = GetWorkRequestResourceId(workRequestResponse, "nodepool"); logger.Info($"Node pool ID is {nodePoolId}"); GetNodePoolRequest getNodePoolRequest = new GetNodePoolRequest { NodePoolId = nodePoolId }; GetNodePoolResponse getNodePoolResponse = await containerEngineClient.GetNodePool(getNodePoolRequest); return(getNodePoolResponse.NodePool); }