diff --git a/go.mod b/go.mod index e2c1f3a..fcbe846 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.12 require ( github.com/gogo/protobuf v1.3.0 // indirect - github.com/oracle/oci-go-sdk v13.0.0+incompatible + github.com/oracle/oci-go-sdk v19.0.0+incompatible github.com/pkg/errors v0.8.1 github.com/rancher/kontainer-engine v0.0.0-20190711161432-b98bad2201bb github.com/rancher/rke v0.2.8 // indirect diff --git a/go.sum b/go.sum index 709c4c6..4ed6e1c 100644 --- a/go.sum +++ b/go.sum @@ -133,6 +133,8 @@ github.com/oracle/oci-go-sdk v7.1.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukw github.com/oracle/oci-go-sdk v13.0.0+incompatible h1:ueAty9OrRXfWi+4gyPLKcOpzhf1OSK70mwt36sD/hf8= github.com/oracle/oci-go-sdk v13.0.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888= github.com/oracle/oci-go-sdk v13.1.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888= +github.com/oracle/oci-go-sdk v19.0.0+incompatible h1:UQnOTZBLEtrqNnJ7jQJiaadScBQ7+CF61+OIvWktkoc= +github.com/oracle/oci-go-sdk v19.0.0+incompatible/go.mod h1:VQb79nF8Z2cwLkLS35ukwStZIg5F66tcBccjip/j888= github.com/oracle/oci-manager v0.0.0-20181210225140-b3f0fa436c6b h1:6HTjRyMR6s3eUEYvrM1nvQ3gIT0RcWOqMoBhzRuzZRM= github.com/oracle/oci-manager v0.0.0-20181210225140-b3f0fa436c6b/go.mod h1:mu49MZKiWx61E+enfYwa8SO2eAcdumsr+eLbXCKfxbs= github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g= diff --git a/oke/oke_manager_client.go b/oke/oke_manager_client.go index 9e147fc..479310f 100644 --- a/oke/oke_manager_client.go +++ b/oke/oke_manager_client.go @@ -56,6 +56,7 @@ const ( type ClusterManagerClient struct { configuration common.ConfigurationProvider containerEngineClient containerengine.ContainerEngineClient + computeClient core.ComputeClient virtualNetworkClient core.VirtualNetworkClient identityClient identity.IdentityClient sleepDuration time.Duration @@ -71,6 +72,11 @@ func NewClusterManagerClient(configuration common.ConfigurationProvider) (*Clust logrus.Debugf("create new ContainerEngine client failed with err %v", err) return nil, err } + coreComputeClient, err := core.NewComputeClientWithConfigurationProvider(configuration) + if err != nil { + logrus.Debugf("create new Compute client failed with err %v", err) + return nil, err + } vNetClient, err := core.NewVirtualNetworkClientWithConfigurationProvider(configuration) if err != nil { logrus.Debugf("create new VirtualNetwork client failed with err %v", err) @@ -84,6 +90,7 @@ func NewClusterManagerClient(configuration common.ConfigurationProvider) (*Clust c := &ClusterManagerClient{ configuration: configuration, containerEngineClient: containerClient, + computeClient: coreComputeClient, virtualNetworkClient: vNetClient, identityClient: identityClient, sleepDuration: 5, @@ -224,11 +231,19 @@ func (mgr *ClusterManagerClient) CreateNodePool(ctx context.Context, state *Stat // Create a node pool for the cluster npReq := containerengine.CreateNodePoolRequest{} + // get Image Id + image, err := getImageID(ctx, mgr.computeClient, state.CompartmentID, state.NodePool.NodeShape, state.NodePool.NodeImageName) + if err != nil { + logrus.Printf("Node ID not found") + npReq.NodeImageName = common.String(state.NodePool.NodeImageName) + } else { + logrus.Printf("Node ID found %v", image.Id) + npReq.NodeSourceDetails = containerengine.NodeSourceViaImageDetails{ImageId: image.Id} + } npReq.Name = common.String(state.Name + "-1") npReq.CompartmentId = common.String(state.CompartmentID) npReq.ClusterId = &state.ClusterID npReq.KubernetesVersion = &state.KubernetesVersion - npReq.NodeImageName = common.String(state.NodePool.NodeImageName) npReq.NodeShape = common.String(state.NodePool.NodeShape) // Node-pool subnet(s) used for node instances in the node pool. // These subnets should be different from the cluster Kubernetes Service LB subnets. @@ -275,6 +290,35 @@ func (mgr *ClusterManagerClient) CreateNodePool(ctx context.Context, state *Stat return nil } +func getImageID(ctx context.Context, c core.ComputeClient, compartment, shape, displayName string) (core.Image, error) { + request := core.ListImagesRequest{ + CompartmentId: common.String(compartment), + OperatingSystem: common.String("Oracle Linux"), + Shape: common.String(shape), + } + r, err := c.ListImages(ctx, request) + + if err != nil { + logrus.Debugf("listing image id's failed with err %v", err) + return core.Image{}, err + } + + index := -1 + for n, i := range r.Items { + if strings.Compare(displayName, *i.DisplayName) == 0 { + index = n + break + } + } + + if index < 0 { + logrus.Debugf("unable to find an image for displayName: %s", displayName) + return core.Image{}, fmt.Errorf("unable to retrieve image %s", displayName) + } + + return r.Items[index], err +} + // GetNodePoolByID returns the node pool with the specified Id, or an error. func (mgr *ClusterManagerClient) GetNodePoolByID(ctx context.Context, nodePoolID string) (containerengine.NodePool, error) {