-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Patryk Strusiewicz-Surmacki <[email protected]>
- Loading branch information
1 parent
f267955
commit e00cb48
Showing
51 changed files
with
3,294 additions
and
602 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Build the manager binary | ||
FROM docker.io/library/golang:1.21-alpine AS builder | ||
|
||
|
||
WORKDIR /workspace | ||
# Copy the Go Modules manifests | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
# cache deps before building and copying source so that we don't need to re-download as much | ||
# and so that source changes don't invalidate our downloaded layer | ||
RUN go mod download | ||
|
||
# Build router | ||
RUN apk add llvm clang linux-headers libbpf-dev musl-dev | ||
|
||
# Copy the go source | ||
COPY cmd/agent/main.go main.go | ||
COPY api/ api/ | ||
COPY controllers/ controllers/ | ||
COPY pkg/ pkg/ | ||
|
||
# Build router | ||
COPY bpf/ bpf/ | ||
RUN cd pkg/bpf/ && go generate | ||
|
||
# Build | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o agent main.go | ||
|
||
FROM alpine:latest | ||
|
||
RUN apk add --no-cache iptables ip6tables | ||
|
||
WORKDIR / | ||
COPY --from=builder /workspace/agent . | ||
USER 65532:65532 | ||
|
||
ENTRYPOINT ["/agent"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
Copyright 2024. | ||
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. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
"crypto/sha256" | ||
"encoding/hex" | ||
"encoding/json" | ||
"fmt" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// NetworkConfigSpec defines the desired state of NetworkConfig. | ||
type NetworkConfigRevisionSpec struct { | ||
// Config stores global configuration of the nodes. | ||
Config NodeNetworkConfigSpec `json:"config"` | ||
// Revision is a hash of the NetworkConfigRevision object that is used to identify the particular revision. | ||
Revision string `json:"revision"` | ||
} | ||
|
||
type NetworkConfigRevisionStatus struct { | ||
// IsInvalid determines if NetworkConfigRevision results in misconfigured nodes (invalid configuration). | ||
IsInvalid bool `json:"isInvalid"` | ||
// Ready informs about how many nodes were already provisioned with a config derived from the revision. | ||
Ready int `json:"ready"` | ||
// Ongoing informs about how many nodes are currently provisioned with a config derived from the revision. | ||
Ongoing int `json:"ongoing"` | ||
// Queued informs about how many nodes are currently waiting to be provisiined with a config derived from the revision. | ||
Queued int `json:"queued"` | ||
// Total informs about how many nodes in total can be provisiined with a config derived from the revision. | ||
Total int `json:"total"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
//+kubebuilder:subresource:status | ||
//+kubebuilder:resource:shortName=ncr,scope=Cluster | ||
//+kubebuilder:printcolumn:name="Invalid",type=string,JSONPath=`.status.isInvalid` | ||
//+kubebuilder:printcolumn:name="Queued",type="integer",JSONPath=".status.queued" | ||
//+kubebuilder:printcolumn:name="Ongoing",type="integer",JSONPath=".status.ongoing" | ||
//+kubebuilder:printcolumn:name="Ready",type="integer",JSONPath=".status.ready" | ||
//+kubebuilder:printcolumn:name="Total",type="integer",JSONPath=".status.total" | ||
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" | ||
|
||
// NetworkConfigRevision is the Schema for the node configuration. | ||
type NetworkConfigRevision struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec NetworkConfigRevisionSpec `json:"spec,omitempty"` | ||
Status NetworkConfigRevisionStatus `json:"status,omitempty"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
|
||
// NetworkConfigRevisionList contains a list of NetworkConfigRevision. | ||
type NetworkConfigRevisionList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []NetworkConfigRevision `json:"items"` | ||
} | ||
|
||
func NewRevision(config *NodeNetworkConfig) (*NetworkConfigRevision, error) { | ||
data, err := json.Marshal(config.Spec) | ||
if err != nil { | ||
return nil, fmt.Errorf("error marshalling data: %w", err) | ||
} | ||
|
||
h := sha256.New() | ||
if _, err := h.Write(data); err != nil { | ||
return nil, fmt.Errorf("failed hashing network config: %w", err) | ||
} | ||
hash := h.Sum(nil) | ||
hashHex := hex.EncodeToString(hash) | ||
|
||
return &NetworkConfigRevision{ | ||
ObjectMeta: metav1.ObjectMeta{Name: hashHex[:10]}, | ||
Spec: NetworkConfigRevisionSpec{ | ||
Config: config.Spec, | ||
Revision: hashHex, | ||
}, | ||
Status: NetworkConfigRevisionStatus{}, | ||
}, nil | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&NetworkConfigRevision{}, &NetworkConfigRevisionList{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
Copyright 2024. | ||
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. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// NodeNetworkConfigSpec defines the desired state of NodeConfig. | ||
type NodeNetworkConfigSpec struct { | ||
// Revision stores hash of the NodeConfigRevision that was used to create the NodeNetworkConfig object. | ||
Revision string `json:"revision"` | ||
Layer2 []Layer2NetworkConfigurationSpec `json:"layer2"` | ||
Vrf []VRFRouteConfigurationSpec `json:"vrf"` | ||
RoutingTable []RoutingTableSpec `json:"routingTable"` | ||
} | ||
|
||
// NodeNetworkConfigStatus defines the observed state of NodeConfig. | ||
type NodeNetworkConfigStatus struct { | ||
// ConfigStatus describes provisioning state od the NodeConfig. Can be either 'provisioning' or 'provisioned'. | ||
ConfigStatus string `json:"configStatus"` | ||
// LastUpdate determines when last update (change) of the ConfigStatus field took place. | ||
LastUpdate metav1.Time `json:"lastUpdate"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
//+kubebuilder:subresource:status | ||
//+kubebuilder:resource:shortName=nnc,scope=Cluster | ||
//+kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.configStatus` | ||
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" | ||
|
||
// NodeNetworkConfig is the Schema for the node configuration. | ||
type NodeNetworkConfig struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec NodeNetworkConfigSpec `json:"spec,omitempty"` | ||
Status NodeNetworkConfigStatus `json:"status,omitempty"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
|
||
// NodeNetworkConfigList contains a list of NodeConfig. | ||
type NodeNetworkConfigList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []NodeNetworkConfig `json:"items"` | ||
} | ||
|
||
func NewEmptyConfig(name string) *NodeNetworkConfig { | ||
return &NodeNetworkConfig{ | ||
ObjectMeta: metav1.ObjectMeta{Name: name}, | ||
Spec: NodeNetworkConfigSpec{ | ||
Vrf: []VRFRouteConfigurationSpec{}, | ||
Layer2: []Layer2NetworkConfigurationSpec{}, | ||
RoutingTable: []RoutingTableSpec{}, | ||
}, | ||
Status: NodeNetworkConfigStatus{ | ||
ConfigStatus: "", | ||
}, | ||
} | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&NodeNetworkConfig{}, &NodeNetworkConfigList{}) | ||
} |
Oops, something went wrong.