Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/evanphx/json-patch v4.9.0+incompatible // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
Expand Down Expand Up @@ -79,7 +79,11 @@ require (
sigs.k8s.io/yaml v1.2.0 // indirect
)

require cloud.google.com/go/compute v1.8.0
require (
cloud.google.com/go/compute v1.8.0
github.com/rs/zerolog v1.27.0
github.com/spf13/cobra v0.0.5
)

require (
github.com/aws/aws-sdk-go-v2/credentials v1.12.14 // indirect
Expand All @@ -92,4 +96,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/sts v1.16.13 // indirect
github.com/aws/smithy-go v1.12.1 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.1.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
)
39 changes: 12 additions & 27 deletions go.sum

Large diffs are not rendered by default.

43 changes: 42 additions & 1 deletion pkg/cluster/kubernetes.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2021 Cisco
// Copyright © 2021, 2022 Cisco
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -133,6 +133,8 @@ func GetEtcdCredentialsSecret(ctx context.Context) (string, string, error) {
return string(secret.Data["username"]), string(secret.Data["password"]), nil
}

// DEPRECATED
// TODO: remove me
func GetOperatorSettingsConfigMap(ctx context.Context) ([]byte, error) {
cli, err := getK8sClientSet()
if err != nil {
Expand Down Expand Up @@ -160,3 +162,42 @@ func GetOperatorSettingsConfigMap(ctx context.Context) ([]byte, error) {

return data, err
}

func GetFilesFromConfigMap(ctx context.Context, nsName, name string) ([][]byte, error) {
cli, err := getK8sClientSet()
if err != nil {
return nil, err
}

cfgm, err := cli.CoreV1().ConfigMaps(nsName).Get(ctx, name, metav1.GetOptions{})
if err != nil {
return nil, err
}

data := [][]byte{}
for _, d := range cfgm.Data {
data = append(data, []byte(d))
}

return data, err
}

func GetFilesFromSecret(ctx context.Context, nsName, name string) ([][]byte, error) {
cli, err := getK8sClientSet()
if err != nil {
return nil, err
}

secret, err := cli.CoreV1().Secrets(nsName).Get(ctx, name, metav1.GetOptions{})
if err != nil {
return nil, err
}

data := [][]byte{}
for _, d := range secret.Data {
data = append(data, d)
break
}

return data, nil
}
13 changes: 11 additions & 2 deletions pkg/cluster/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const (
)

type NetworkConfiguration struct {
PlatformName string
NetworkName string
SubNetworkName string
}
Expand Down Expand Up @@ -126,7 +127,11 @@ func GetNetworkFromGKE(ctx context.Context, opts ...gcoption.ClientOption) (*Net
return nil, err
}

return &NetworkConfiguration{cluster.Network, cluster.Subnetwork}, nil
return &NetworkConfiguration{
PlatformName: string(GKECluster),
NetworkName: cluster.Network,
SubNetworkName: cluster.Subnetwork,
}, nil
}

// GetNetworkFromEKS returns the network from EKS.
Expand Down Expand Up @@ -167,7 +172,11 @@ func GetNetworkFromEKS(ctx context.Context, cfgs ...*aws.Config) (*NetworkConfig
}

inst := out.Reservations[0].Instances[0]
return &NetworkConfiguration{aws.StringValue(inst.VpcId), aws.StringValue(inst.SubnetId)}, nil
return &NetworkConfiguration{
PlatformName: string(EKSCluster),
NetworkName: aws.StringValue(inst.VpcId),
SubNetworkName: aws.StringValue(inst.SubnetId),
}, nil
}

// GetGCPRegion attempts to get the region where GKE is running in.
Expand Down
37 changes: 37 additions & 0 deletions pkg/command/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright © 2022 Cisco
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0

package command

import (
"github.com/CloudNativeSDWAN/cnwan-operator/pkg/command/run"
"github.com/spf13/cobra"
)

func GetRootCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "cnwan-operator [COMMAND] [OPTIONS]",
Short: "Watch and synchronize your Kubernetes services on a service registry.",
Example: "cnwan-operator run service-directory --default-region us-east1",
}

// Commands
cmd.AddCommand(run.GetRunCommand())

return cmd
}
Loading