-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
735 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
OCI_COMPARTMENT_ID=lyridinc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module echo | ||
|
||
go 1.17 | ||
|
||
require ( | ||
github.com/oracle/oci-go-sdk v24.3.0+incompatible | ||
github.com/oracle/oci-go-sdk/v65 v65.15.0 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/gofrs/flock v0.8.1 // indirect | ||
github.com/sony/gobreaker v0.5.0 // indirect | ||
github.com/stretchr/testify v1.7.0 // indirect | ||
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= | ||
github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= | ||
github.com/oracle/oci-go-sdk v24.3.0+incompatible h1:x4mcfb4agelf1O4/1/auGlZ1lr97jXRSSN5MxTgG/zU= | ||
github.com/oracle/oci-go-sdk v24.3.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888= | ||
github.com/oracle/oci-go-sdk/v65 v65.15.0 h1:JfpvqeNXQ+8rPpUEs/Bhj4VazSK4GeUTpuH6IvqxDRY= | ||
github.com/oracle/oci-go-sdk/v65 v65.15.0/go.mod h1:oyMrMa1vOzzKTmPN+kqrTR9y9kPA2tU1igN3NUSNTIE= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/sony/gobreaker v0.5.0 h1:dRCvqm0P490vZPmy7ppEk2qCnCieBooFJ+YoXGYB+yg= | ||
github.com/sony/gobreaker v0.5.0/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY= | ||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | ||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= | ||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c= | ||
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package helper | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
"github.com/oracle/oci-go-sdk/v65/common" | ||
"github.com/oracle/oci-go-sdk/v65/containerengine" | ||
"github.com/oracle/oci-go-sdk/v65/core" | ||
"github.com/oracle/oci-go-sdk/v65/example/helpers" | ||
"github.com/oracle/oci-go-sdk/v65/identity" | ||
) | ||
|
||
var ( | ||
compartmentId = "ocid1.tenancy.oc1..aaaaaaaaspsylihi2umh6cz3zkkdzkcstcv2kpbjycrqehm34tpudyxufvna" | ||
clusterName = "clustersdk" | ||
vcnDisplayName = "clustersdkvcn" | ||
subnetDisplayName1 = "OCI-GOSDK-Az-k8sSubnet" | ||
subnetDisplayName2 = "OCI-GOSDK-Az-nodeSubnet" | ||
subnetDisplayName3 = "OCI-GOSDK-Az-svcSubnet" | ||
nodePoolName = "pool1" | ||
kubeVersion = "v1.22.5" | ||
) | ||
|
||
func Experiment1() { | ||
ctx := context.Background() | ||
c, clerr := containerengine.NewContainerEngineClientWithConfigurationProvider(common.DefaultConfigProvider()) | ||
helpers.FatalIfError(clerr) | ||
|
||
compute, err := core.NewComputeClientWithConfigurationProvider(common.DefaultConfigProvider()) | ||
helpers.FatalIfError(err) | ||
|
||
identityClient, err := identity.NewIdentityClientWithConfigurationProvider(common.DefaultConfigProvider()) | ||
helpers.FatalIfError(err) | ||
req := identity.ListAvailabilityDomainsRequest{} | ||
req.CompartmentId = common.String(compartmentId) | ||
ads, err := identityClient.ListAvailabilityDomains(ctx, req) | ||
helpers.FatalIfError(err) | ||
|
||
vcn := CreateVcn(vcnDisplayName, compartmentId, clusterName) | ||
|
||
fmt.Println("WAITING") | ||
time.Sleep(5 * 60 * time.Second) | ||
|
||
internetGateway := CreateInternetGateway(*vcn.Id, compartmentId) | ||
fmt.Println("WAITING") | ||
time.Sleep(5 * 60 * time.Second) | ||
|
||
natGateway := CreateNatGateway(*vcn.Id, compartmentId) | ||
fmt.Println("WAITING") | ||
time.Sleep(5 * 60 * time.Second) | ||
|
||
serviceGateway := CreateServiceGateway(*vcn.Id, compartmentId) | ||
fmt.Println("WAITING") | ||
time.Sleep(5 * 60 * time.Second) | ||
|
||
publicRouteTable := CreatePublicRouteTable(*vcn.Id, compartmentId, *internetGateway.Id) | ||
fmt.Println("WAITING") | ||
time.Sleep(5 * 60 * time.Second) | ||
|
||
privateRouteTable := CreatePrivateRouteTable(*vcn.Id, compartmentId, *natGateway.Id, *serviceGateway.Id) | ||
fmt.Println("WAITING") | ||
time.Sleep(5 * 60 * time.Second) | ||
|
||
svcSubnet := CreateSubnet(&subnetDisplayName3, common.String("10.0.20.0/24"), common.String("svcSubnetDns"), nil, vcn, publicRouteTable, nil) // svc subnet | ||
fmt.Println("WAITING") | ||
time.Sleep(5 * 60 * time.Second) | ||
|
||
k8sSecurityList := CreateK8sSecurityList(*vcn.Id, compartmentId) | ||
k8sSubnet := CreateSubnet(&subnetDisplayName1, common.String("10.0.0.0/28"), common.String("k8sSubnetDns"), nil, vcn, publicRouteTable, &k8sSecurityList) | ||
fmt.Println("WAITING") | ||
time.Sleep(5 * 60 * time.Second) | ||
|
||
nodeSecurityList := CreateNodeSecurityList(*vcn.Id, compartmentId) | ||
nodeSubnet := CreateSubnet(&subnetDisplayName2, common.String("10.0.10.0/24"), common.String("nodeSubnetDns"), nil, vcn, privateRouteTable, &nodeSecurityList) | ||
fmt.Println("WAITING") | ||
time.Sleep(5 * 60 * time.Second) | ||
|
||
createClusterResponse := CreateCluster(ctx, c, *vcn.Id, compartmentId, *svcSubnet.Id, *k8sSubnet.Id, clusterName, kubeVersion) | ||
|
||
// wait until work request complete | ||
workReqResp := waitUntilWorkRequestComplete(c, createClusterResponse.OpcWorkRequestId) | ||
fmt.Println("cluster created") | ||
fmt.Println("WAITING") | ||
time.Sleep(5 * 60 * time.Second) | ||
|
||
clusterID := getResourceID(workReqResp.Resources, containerengine.WorkRequestResourceActionTypeCreated, "CLUSTER") | ||
|
||
// id := k8sSubnet.Id | ||
// fmt.Println("ID:", *clusterID, *id) | ||
// migrateClusterResponse := MigrateToVcnNativeCluster(ctx, c, *clusterID, *id) | ||
// migreateReqResp := waitUntilWorkRequestComplete(c, migrateClusterResponse.OpcWorkRequestId) | ||
// fmt.Println("cluster migrated") | ||
|
||
// // wait until migrate complete | ||
// getResourceID(migreateReqResp.Resources, containerengine.WorkRequestResourceActionTypeCreated, "CLUSTER") | ||
|
||
// // get Image Id | ||
image := getImageID(ctx, compute) | ||
|
||
fmt.Println(image) | ||
CreateNodePool(nodePoolName, kubeVersion, *clusterID, *image.Id, compartmentId, *nodeSubnet.Id, ads) | ||
|
||
// AFTER COMPLETION: create tutorial on GitHub and Notion | ||
} | ||
|
||
func waitUntilWorkRequestComplete(client containerengine.ContainerEngineClient, workReuqestID *string) containerengine.GetWorkRequestResponse { | ||
// retry GetWorkRequest call until TimeFinished is set | ||
shouldRetryFunc := func(r common.OCIOperationResponse) bool { | ||
return r.Response.(containerengine.GetWorkRequestResponse).TimeFinished == nil | ||
} | ||
|
||
getWorkReq := containerengine.GetWorkRequestRequest{ | ||
WorkRequestId: workReuqestID, | ||
RequestMetadata: helpers.GetRequestMetadataWithCustomizedRetryPolicy(shouldRetryFunc), | ||
} | ||
|
||
getResp, err := client.GetWorkRequest(context.Background(), getWorkReq) | ||
helpers.FatalIfError(err) | ||
return getResp | ||
} | ||
|
||
// getResourceID return a resource ID based on the filter of resource actionType and entityType | ||
func getResourceID(resources []containerengine.WorkRequestResource, actionType containerengine.WorkRequestResourceActionTypeEnum, entityType string) *string { | ||
for _, resource := range resources { | ||
if resource.ActionType == actionType && strings.ToUpper(*resource.EntityType) == entityType { | ||
return resource.Identifier | ||
} | ||
} | ||
|
||
fmt.Println("cannot find matched resources") | ||
return nil | ||
} | ||
|
||
func getImageID(ctx context.Context, c core.ComputeClient) core.Image { | ||
request := core.ListImagesRequest{ | ||
CompartmentId: common.String(compartmentId), | ||
// OperatingSystem: common.String("Oracle Linux"), | ||
// Shape: common.String("VM.Standard.E3.Flex"), | ||
DisplayName: common.String("Oracle-Linux-7.9-2022.06.30-0"), | ||
} | ||
|
||
r, err := c.ListImages(ctx, request) | ||
helpers.FatalIfError(err) | ||
|
||
return r.Items[0] | ||
} |
Oops, something went wrong.