Skip to content

Commit

Permalink
Merge pull request #80 from srl-labs/refactor/api-overhaul
Browse files Browse the repository at this point in the history
Refactor/api overhaul
  • Loading branch information
carlmontanari authored Dec 2, 2023
2 parents 9f7e548 + 45cc019 commit c4c44e2
Show file tree
Hide file tree
Showing 100 changed files with 2,732 additions and 4,837 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ jobs:
set -x
kubectl get pods -n clabernetes -o yaml
echo "********************************"
echo "**** events ****
echo "**** events ****"
echo "********************************"
kubectl get events -n clabernetes --sort-by='.lastTimestamp'
echo "********************************"
echo "**** logs ****
echo "**** logs ****"
echo "********************************"
kubectl logs -l clabernetes/name=clabernetes-manager -n clabernetes --tail=-1
exit 1
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ run-client-gen: ## Run client-gen
GOMOD111=on \
client-gen \
--go-header-file hack/boilerplate.go.txt \
--input-base github.com/srl-labs/clabernetes/apis \
--input topology/v1alpha1 \
--input-base github.com/srl-labs/clabernetes \
--input apis/v1alpha1 \
--trim-path-prefix ${GOPATH}/src/github.com/srl-labs/clabernetes \
--output-package github.com/srl-labs/clabernetes/generated \
--clientset-name clientset
Expand Down
17 changes: 17 additions & 0 deletions apis/doc.go
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
package apis

const (
// Group is the main (only!) group for clabernetes CRDs.
Group = "clabernetes.containerlab.dev"

// Topology is the Kind of the Topology custom resource.
Topology = "topology"

// TopologyKindContainerlab is the "containerlab" kind of topology.
TopologyKindContainerlab = "containerlab"

// TopologyKindKne is the "kne" kind of topology.
TopologyKindKne = "kne"

// TopologyKindUnknown is the kind of topology for unknown topologies.
TopologyKindUnknown = "unknown"
)
12 changes: 0 additions & 12 deletions apis/topology/doc.go

This file was deleted.

59 changes: 0 additions & 59 deletions apis/topology/v1alpha1/containerlab.go

This file was deleted.

58 changes: 0 additions & 58 deletions apis/topology/v1alpha1/kne.go

This file was deleted.

4 changes: 2 additions & 2 deletions apis/topology/v1alpha1/doc.go → apis/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen=package,register
// +groupName=topology.clabernetes
package v1alpha1 // import "github.com/srl-labs/clabernetes/apis/topology/v1alpha1"
// +groupName=clabernetes.containerlab.dev
package v1alpha1 // import "github.com/srl-labs/clabernetes/apis/v1alpha1"
18 changes: 4 additions & 14 deletions apis/topology/v1alpha1/register.go → apis/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package v1alpha1

import (
"fmt"

clabernetesapistopology "github.com/srl-labs/clabernetes/apis/topology"
clabernetesconstants "github.com/srl-labs/clabernetes/constants"

clabernetesapis "github.com/srl-labs/clabernetes/apis"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

apimachineryruntime "k8s.io/apimachinery/pkg/runtime"
Expand All @@ -24,11 +20,7 @@ var (

// SchemeGroupVersion is group version used to register these objects.
var SchemeGroupVersion = apimachineryscheme.GroupVersion{
Group: fmt.Sprintf(
"%s.%s",
clabernetesapistopology.Group,
clabernetesconstants.Clabernetes,
),
Group: clabernetesapis.Group,
Version: Version,
}

Expand All @@ -50,9 +42,7 @@ func addKnownTypes(scheme *apimachineryruntime.Scheme) error {
// GetAPIs returns the information necessary to register this package's types to a scheme.
func GetAPIs() (apimachineryscheme.GroupVersion, []apimachineryruntime.Object) {
return SchemeGroupVersion, []apimachineryruntime.Object{
&Containerlab{},
&ContainerlabList{},
&Kne{},
&KneList{},
&Topology{},
&TopologyList{},
}
}
68 changes: 68 additions & 0 deletions apis/v1alpha1/topology.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// Topology is an object that holds information about a clabernetes Topology -- that is, a valid
// topology file (ex: containerlab topology), and any associated configurations.
// +k8s:openapi-gen=true
// +kubebuilder:resource:path="topologies"
// +kubebuilder:printcolumn:JSONPath=".status.kind",name=Kind,type=string
type Topology struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec TopologySpec `json:"spec,omitempty"`
Status TopologyStatus `json:"status,omitempty"`
}

// TopologySpec is the spec for a Topology resource.
type TopologySpec struct {
// Definition defines the actual set of nodes (network ones, not k8s ones!) that this Topology
// CR represents. Historically, and probably most often, this means Topology holds a "normal"
// containerlab topology file that will be "clabernetsified", however this could also be a "kne"
// config, or perhaps others in the future.
Definition Definition `json:"definition"`
// Expose holds configurations relevant to how clabernetes exposes a topology.
// +optional
Expose Expose `json:"expose"`
// Deployment holds configurations relevant to how clabernetes configures deployments that make
// up a given topology.
// +optional
Deployment Deployment `json:"deployment"`
// ImagePull holds configurations relevant to how clabernetes launcher pods handle pulling
// images.
// +optional
ImagePull ImagePull `json:"imagePull"`
}

// TopologyStatus is the status for a Containerlab topology resource.
type TopologyStatus struct {
// Kind is the topology kind this CR represents -- for example "containerlab".
// +kubebuilder:validation:Enum=containerlab;kne
Kind string `json:"kind"`
// ReconcileHashes holds the hashes form the last reconciliation run.
ReconcileHashes ReconcileHashes `json:"reconcileHashes"`
// Configs is a map of node name -> containerlab config -- in other words, this is the original
// Topology.Spec.Definition converted to containerlab "sub-topologies" The actual
// "sub-topologies"/"sub-configs" are stored as a string -- this is the actual containerlab
// topology that gets mounted in the launcher pod.
Configs map[string]string `json:"configs"`
// ExposedPorts holds a map of (containerlab not k8s!) nodes and their exposed ports
// (via load balancer).
ExposedPorts map[string]*ExposedPorts `json:"exposedPorts"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// TopologyList is a list of Topology objects.
type TopologyList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

Items []Topology `json:"items"`
}
Loading

0 comments on commit c4c44e2

Please sign in to comment.