Skip to content

Commit

Permalink
Merge pull request #61 from srl-labs/tests/topology-tests
Browse files Browse the repository at this point in the history
Tests/topology tests
  • Loading branch information
carlmontanari authored Oct 22, 2023
2 parents 0cbd254 + d390e57 commit cf31894
Show file tree
Hide file tree
Showing 61 changed files with 5,755 additions and 2,273 deletions.
4 changes: 4 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ issues:
- funlen
- gochecknoglobals

- path: logging/fake.go
linters:
- revive

# ignore globals for standard k8s things
- linters:
- gochecknoglobals
Expand Down
4 changes: 3 additions & 1 deletion clabverter/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"strings"
"text/template"

clabernetesutilkubernetes "github.com/srl-labs/clabernetes/util/kubernetes"

clabernetesutil "github.com/srl-labs/clabernetes/util"
clabernetesutilcontainerlab "github.com/srl-labs/clabernetes/util/containerlab"
)
Expand Down Expand Up @@ -262,7 +264,7 @@ func (c *Clabverter) handleExtraFiles() error {
c.extraFilesConfigMaps[nodeName] = make([]topologyConfigMapTemplateVars, 0)

for extraFilePath, extraFileContent := range nodeExtraFiles {
safeFileName := clabernetesutil.SafeConcatNameKubernetes(
safeFileName := clabernetesutilkubernetes.SafeConcatNameKubernetes(
strings.Split(extraFilePath, "/")...)

safeFileName = strings.TrimPrefix(safeFileName, "-")
Expand Down
6 changes: 4 additions & 2 deletions clicker/clabernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"sync"
"time"

clabernetesutilkubernetes "github.com/srl-labs/clabernetes/util/kubernetes"

"gopkg.in/yaml.v3"

claberneteserrors "github.com/srl-labs/clabernetes/errors"
Expand Down Expand Up @@ -203,7 +205,7 @@ func (c *clabernetes) run() error {
func (c *clabernetes) setup() error {
var err error

c.namespace, err = clabernetesutil.CurrentNamespace()
c.namespace, err = clabernetesutilkubernetes.CurrentNamespace()
if err != nil {
c.logger.Criticalf("failed getting current namespace, err: %s", err)

Expand Down Expand Up @@ -318,7 +320,7 @@ func envToResources() (k8scorev1.ResourceRequirements, error) {
return out, nil
}

parsedOut, err := clabernetesutil.YAMLToK8sResourceRequirements(asStr)
parsedOut, err := clabernetesutilkubernetes.YAMLToK8sResourceRequirements(asStr)
if err != nil {
return out, err
}
Expand Down
3 changes: 3 additions & 0 deletions config/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ var (
managerInstanceOnce sync.Once //nolint:gochecknoglobals
)

// ManagerGetterFunc returns an instance of the config manager.
type ManagerGetterFunc func() Manager

// InitManager initializes the config manager -- it does this once only, its a no-op if the manager
// is already initialized.
func InitManager(ctx context.Context, appName, namespace string, client *kubernetes.Clientset) {
Expand Down
18 changes: 18 additions & 0 deletions constants/kubernetes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package constants

const (
// KubernetesConfigMap is a const to use for "configmap".
KubernetesConfigMap = "configmap"

// KubernetesService is a const to use for "service".
KubernetesService = "service"

// KubernetesDeployment is a const to use for "deployment".
KubernetesDeployment = "deployment"

// KubernetesServiceClusterIPType is a const to use for "ClusterIP".
KubernetesServiceClusterIPType = "ClusterIP"

// KubernetesServiceLoadBalancerType is a const to use for "LoadBalancer".
KubernetesServiceLoadBalancerType = "LoadBalancer"
)
13 changes: 12 additions & 1 deletion controllers/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

clabernetesutilkubernetes "github.com/srl-labs/clabernetes/util/kubernetes"

ctrlruntimeevent "sigs.k8s.io/controller-runtime/pkg/event"
ctrlruntimepredicate "sigs.k8s.io/controller-runtime/pkg/predicate"

Expand Down Expand Up @@ -58,7 +60,7 @@ func NewBaseController(
return &BaseController{
Ctx: ctx,
AppName: appName,
ControllerNamespace: clabernetesutil.MustCurrentNamespace(),
ControllerNamespace: clabernetesutilkubernetes.MustCurrentNamespace(),
Log: logger,
Config: config,
Client: client,
Expand Down Expand Up @@ -127,3 +129,12 @@ func (c *BaseController) LogReconcileCompleteObjectNotExist(_ ctrlruntime.Reques
func (c *BaseController) LogReconcileFailedGettingObject(req ctrlruntime.Request, err error) {
c.Log.Criticalf("failed fetching '%s/%s', error: %s", req.Namespace, req.Name, err)
}

// GetServiceDNSSuffix returns the default "svc.cluster.local" dns suffix, or the user's provided
// override value.
func (c *BaseController) GetServiceDNSSuffix() string {
return clabernetesutil.GetEnvStrOrDefault(
clabernetesconstants.InClusterDNSSuffixEnv,
clabernetesconstants.DefaultInClusterDNSSuffix,
)
}
56 changes: 0 additions & 56 deletions controllers/deployments.go

This file was deleted.

31 changes: 0 additions & 31 deletions controllers/services.go

This file was deleted.

159 changes: 0 additions & 159 deletions controllers/topology/configmap.go

This file was deleted.

Loading

0 comments on commit cf31894

Please sign in to comment.