Skip to content

Commit

Permalink
Set default cni for get cluster calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Inbaraj-S committed Jun 4, 2024
1 parent b6d7df4 commit 382e0f4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
3 changes: 1 addition & 2 deletions pkg/server/config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ clusters:
- name: cluster-ckmntg4fska
cluster:
server: https://129.80.70.29:6443
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURpVENDQW5HZ0F3SUJBZ0lSQU5GbG9rWEVxOTgyTGNwUmE4YUxDREF3RFFZSktvWklodmNOQVFFTEJRQXcKWGpFUE1BMEdBMVVFQXd3R1N6aHpJRU5CTVFzd0NRWURWUVFHRXdKVlV6RVBNQTBHQTFVRUJ3d0dRWFZ6ZEdsdQpNUTh3RFFZRFZRUUtEQVpQY21GamJHVXhEREFLQmdOVkJBc01BMDlqYVRFT01Bd0dBMVVFQ0F3RlZHVjRZWE13CkhoY05Nak13TXpFME1EVTFOVEF5V2hjTk1qZ3dNekUwTURVMU5UQXlXakJlTVE4d0RRWURWUVFEREFaTE9ITWcKUTBFeEN6QUpCZ05WQkFZVEFsVlRNUTh3RFFZRFZRUUhEQVpCZFhOMGFXNHhEekFOQmdOVkJBb01Cazl5WVdOcwpaVEVNTUFvR0ExVUVDd3dEVDJOcE1RNHdEQVlEVlFRSURBVlVaWGhoY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCCkJRQURnZ0VQQURDQ0FRb0NnZ0VCQUw5Mjl1M3h5YVJaNW42U20vb09PZWtwejUzRUxCejNWZ3BqWFRxeW9RL2sKaDl4NzBOQkNxZ2pmUUpWMWF3aE9Md24rQ1kwWkZvdkVQTE5GOHliSGh2NHdHTEVSRTNQWDY2cHFacS9LbEliOQpZRUJyY0xueEdLV1NKLzRlZ0N1UW5PMjRIQnQzam95LzdLSnphNms3ZnNYQ0pJOG13VGFXVkt1cm4yeE41TmFECm1PZDRVM0QyMmY0dUNzdDRYYTNnV1hqWUhqMkp5S3ZmWUMwdzNUU2VrbEZOTEdwQjFGNHVGT1REdzNyZktLSUYKVHo2SVpHemg0dzZ6SElGa3hzTWxhYzhYRHYvcTd4cW5XRHV3Ny9YaDMrRFR0R29sNnpweUU3a2JGeUpSdjRlRgpOd0NWVk1CSGZOcDFBVUJTZWR6RkwyQ05qc1AxeGtqTFppdXhqcjh1UXBrQ0F3RUFBYU5DTUVBd0R3WURWUjBUCkFRSC9CQVV3QXdFQi96QU9CZ05WSFE4QkFmOEVCQU1DQVFZd0hRWURWUjBPQkJZRUZIcjQ2dzhPVUxhZWo5ck0KUWFGMm4vQ2JoNkNMTUEwR0NTcUdTSWIzRFFFQkN3VUFBNElCQVFDb0ZZOGlwQUtmaWQ3QVVSMU80QUNQYWJHeQpBbnJ1aEJtTVphbWo1MUwvLzhtcVlQckxiZ09BUFlnZEVqb0pFOUJOS1dEbDM3bUl3bmwyUkV1TVNUbkxIdTdQClRzY1ZyazZROGJyS2FtalQrSjA0UHRPSytoMG9QSWUyenZtNStJcVcvQW1ET0FQQWd3WTZ1ZFkvNkllYzUrSUcKZzBjQzZMUDdQK2FMMnhHRXcvYkNJQThaZE44MTB2c05GcE56TS80MkdwL0QvanhiY2R5R3JHMGY2dnFKZ1I1dgo4TjFnR2lzSEtsZktpdE5aT3BVQmNjV3hmY0J4eUUvQzJmZktEOVZLYTdYcjZSQzA5T3cxRFJuUW8waEtab1VmClVKNEY1a28vVnhPUU9jdmhkbmxqSkYxK1cwSnMvWkJuZEdlWUUra1YvZmw1VE9xTjBoZk8xOUlaSWhCSAotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
users:
- name: user-ckmntg4fska
user:
Expand All @@ -17,7 +16,7 @@ users:
- cluster
- generate-token
- --cluster-id
- ocid1.cluster.oc1.iad.aaaaaaaafwztfxvg7aksgmlcjfemq4zoce34x66i3wknnt377ckmntg4fska
- ocid1.cluster.oc1.iad.aaaaaaaafwztfxvg7aks___ckmntg4fska
- --region
- us-ashburn-1
env: []
Expand Down
33 changes: 18 additions & 15 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package server

import (
"context"
"fmt"
"net/http"
"os"

Expand Down Expand Up @@ -148,29 +147,33 @@ func SetUpControllers(opts types.IngressOpts, ingressClassInformer networkinginf
}

func fetchCniType(id string, client *containerengine.ContainerEngineClient) (string, error) {
resp := getCluster(id, client)
return GetCniFromCluster(resp)
}

// Create a request and dependent object(s).
req := containerengine.GetClusterRequest{ClusterId: common.String(id)}

// Send the request using the service client
resp, err := client.GetCluster(context.Background(), req)
if err != nil {
klog.Fatalf("failed to get cluster details: %v", err)
}
cni := resp.Cluster.ClusterPodNetworkOptions

func GetCniFromCluster(resp containerengine.Cluster) (string, error) {
cni := resp.ClusterPodNetworkOptions
for _, n := range cni {
switch n.(type) {
case containerengine.FlannelOverlayClusterPodNetworkOptionDetails:
return string(containerengine.ClusterPodNetworkOptionDetailsCniTypeFlannelOverlay), nil
case containerengine.OciVcnIpNativeClusterPodNetworkOptionDetails:
return string(containerengine.ClusterPodNetworkOptionDetailsCniTypeOciVcnIpNative), nil
default:
return "", fmt.Errorf("unsupported CNI found in Cluster : %v", n)
return string(containerengine.ClusterPodNetworkOptionDetailsCniTypeFlannelOverlay), nil
}
}
return string(containerengine.ClusterPodNetworkOptionDetailsCniTypeFlannelOverlay), nil
}

func getCluster(id string, client *containerengine.ContainerEngineClient) containerengine.Cluster {
// Create a request and dependent object(s).
req := containerengine.GetClusterRequest{ClusterId: common.String(id)}

return "", fmt.Errorf("no CNI found in Cluster")
// Send the request using the service client
resp, err := client.GetCluster(context.Background(), req)
if err != nil {
klog.Fatalf("failed to get cluster details: %v", err)
}
return resp.Cluster
}

func setupClient(ctx context.Context, opts types.IngressOpts, k8client clientset.Interface) *client.ClientProvider {
Expand Down
14 changes: 14 additions & 0 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

. "github.com/onsi/gomega"
. "github.com/oracle/oci-go-sdk/v65/containerengine"
)

func TestKubeConfig(t *testing.T) {
Expand All @@ -12,3 +13,16 @@ func TestKubeConfig(t *testing.T) {
Expect(err == nil && cfg != nil).Should(Equal(true))
Expect(cfg.Host).Should(Equal("https://129.80.70.29:6443"))
}

func TestGetCniFromCluster(t *testing.T) {
RegisterTestingT(t)
ns := make([]ClusterPodNetworkOptionDetails, 1)

// No value test
resp := Cluster{
ClusterPodNetworkOptions: ns,
}
cni, err := GetCniFromCluster(resp)
Expect(cni).Should(Equal(string(ClusterPodNetworkOptionDetailsCniTypeFlannelOverlay)))
Expect(err).Should(BeNil())
}

0 comments on commit 382e0f4

Please sign in to comment.