Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nephio operator for focom to oran-provisioning requests #849

Merged
merged 29 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ff7aacb
Focom operator inital import
dek5troza Feb 5, 2025
57e8f7f
Add go.mod
efiacor Feb 5, 2025
6533314
Add go.mod
efiacor Feb 5, 2025
83b892a
Update focom-op IMG tag
efiacor Feb 5, 2025
5d42364
Update import paths to nephio
efiacor Feb 5, 2025
92496b6
Refactor operator example kpt pkg
efiacor Feb 5, 2025
134bfbc
Add/Update copyright headers
efiacor Feb 5, 2025
800e6a2
Rename yaml file
efiacor Feb 5, 2025
4660976
Commit header change after make
efiacor Feb 5, 2025
ff125a2
Update readme file with information on e2e test and testenv
dek5troza Feb 5, 2025
f55203c
Update image tag in e2e suite
efiacor Feb 5, 2025
9bf5133
Fix failing presumit unit test
efiacor Feb 5, 2025
36d3695
Fix failing gosec runs
efiacor Feb 5, 2025
88437f8
Exclude test and generated files from gosec
efiacor Feb 5, 2025
57308ec
Fix golangci-lint failing jobs
efiacor Feb 5, 2025
caa97d0
Remove unknown golint flag
efiacor Feb 5, 2025
da6e22b
Use lates gotests infra image for test
efiacor Feb 5, 2025
cee0183
Use top level go-misc make targets
efiacor Feb 5, 2025
c8a8293
Use latest gotests for make gosec target
efiacor Feb 5, 2025
b703689
Ignore gosec results files
efiacor Feb 5, 2025
b293a9d
Fix golangci-lint job
efiacor Feb 5, 2025
a0079d9
Use latest gotests for golangci-lint
efiacor Feb 5, 2025
b265b9e
Fix krm-func lib linting errors
efiacor Feb 5, 2025
3f31406
Update prow to use lates gotests image
efiacor Feb 5, 2025
59cf850
Update default-go-lint.mk
efiacor Feb 6, 2025
77d2a41
Remove hardcoding of o2ims CRD
efiacor Feb 10, 2025
5b25952
Remove unused CR
efiacor Feb 11, 2025
9ffbec5
Add missing rbac roles
efiacor Feb 12, 2025
de62d50
Run make fmt
efiacor Feb 12, 2025
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ vendor
go.work
go.work.sum
lcov.info

# go tools artifacts
coverage_unit.html
*-results.html
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
run:
build-tags:
- "-buildvcs=false"
timeout: 10m

issues:
exclude-dirs:
- "vendor"
- "test"

exclude-files:
- ".*\\_test.go$"
Expand Down
10 changes: 5 additions & 5 deletions .prow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ presubmits:
always_run: true
spec:
containers:
- image: nephio/gotests:1817817865340850176
- image: nephio/gotests:1885274380137664512
command:
- make
args:
Expand All @@ -14,7 +14,7 @@ presubmits:
always_run: true
spec:
containers:
- image: nephio/gotests:1817817865340850176
- image: nephio/gotests:1885274380137664512
command:
- make
args:
Expand All @@ -24,7 +24,7 @@ presubmits:
always_run: true
spec:
containers:
- image: nephio/gotests:1817817865340850176
- image: nephio/gotests:1885274380137664512
command:
- make
args:
Expand All @@ -34,7 +34,7 @@ presubmits:
always_run: true
spec:
containers:
- image: nephio/gotests:1817817865340850176
- image: nephio/gotests:1885274380137664512
command:
- "/bin/sh"
- "-c"
Expand Down Expand Up @@ -74,7 +74,7 @@ presubmits:
always_run: true
spec:
containers:
- image: nephio/gotests:1817817865340850176
- image: nephio/gotests:1885274380137664512
command:
- "/usr/local/bin/lichen.sh"

Expand Down
7 changes: 3 additions & 4 deletions default-go-lint.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 The Nephio Authors.
# Copyright 2023,2025 The Nephio Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,8 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.


GOLANG_CI_VER ?= v1.57
GOLANG_CI_VER ?= v1.63.4
GIT_ROOT_DIR ?= $(dir $(lastword $(MAKEFILE_LIST)))
include $(GIT_ROOT_DIR)/detect-container-runtime.mk

Expand All @@ -22,7 +21,7 @@ include $(GIT_ROOT_DIR)/detect-container-runtime.mk
lint: ## Run Go linter against the codebase
ifeq ($(CONTAINER_RUNNABLE), 0)
$(RUN_CONTAINER_COMMAND) docker.io/golangci/golangci-lint:${GOLANG_CI_VER}-alpine \
golangci-lint run ./... -v
golangci-lint run ./... -v
else
golangci-lint run ./... -v
endif
4 changes: 1 addition & 3 deletions default-go-test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.


GO_VERSION ?= 1.22.2
TEST_COVERAGE_FILE=lcov.info
TEST_COVERAGE_HTML_FILE=coverage_unit.html
TEST_COVERAGE_FUNC_FILE=func_coverage.out
Expand All @@ -28,7 +26,7 @@ unit: test
.PHONY: test
test: ## Run unit tests (go test)
ifeq ($(CONTAINER_RUNNABLE), 0)
$(RUN_CONTAINER_COMMAND) docker.io/library/golang:${GO_VERSION}-alpine3.19 \
$(RUN_CONTAINER_COMMAND) docker.io/nephio/gotests:1885274380137664512 \
Copy link
Contributor

@vjayaramrh vjayaramrh Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the rationale not to use a generally available golang container image? Thanks

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plan is to move the presubmits for here and porch to use this common image coming form the test-infra project.
https://github.com/nephio-project/test-infra/blob/main/images/gotests/Dockerfile

sh -e -c "go test ./... -v -coverprofile ${TEST_COVERAGE_FILE}; \
go tool cover -html=${TEST_COVERAGE_FILE} -o ${TEST_COVERAGE_HTML_FILE}; \
go tool cover -func=${TEST_COVERAGE_FILE} -o ${TEST_COVERAGE_FUNC_FILE}"
Expand Down
6 changes: 3 additions & 3 deletions default-gosec.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

GOSEC_VER ?= 2.15.0
GIT_ROOT_DIR ?= $(dir $(lastword $(MAKEFILE_LIST)))
include $(GIT_ROOT_DIR)/detect-container-runtime.mk

# Install link at https://github.com/securego/gosec#install if not running inside a container
.PHONY: gosec
gosec: ## Inspect the source code for security problems by scanning the Go Abstract Syntax Tree
ifeq ($(CONTAINER_RUNNABLE), 0)
$(RUN_CONTAINER_COMMAND) docker.io/securego/gosec:${GOSEC_VER} ./...
$(RUN_CONTAINER_COMMAND) docker.io/nephio/gotests:1885274380137664512 gosec -fmt=html -out=gosec-results.html \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use the regular available gosec image? Thanks

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plan is to move the presubmits for here and porch to use this common image coming form the test-infra project.
https://github.com/nephio-project/test-infra/blob/main/images/gotests/Dockerfile

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@efiacor Appreciate the response,
From what I understand regarding container best practices, you want a container to contain only one application.

-stdout -verbose=text -exclude-dir=test -exclude-generated ./...
else
gosec ./...
gosec -fmt=html -out=gosec-results.html -stdout -verbose=text -exclude-dir=test -exclude-generated ./...
endif
9 changes: 5 additions & 4 deletions krm-functions/lib/condkptsdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ limitations under the License.
package condkptsdk

import (
"errors"
"fmt"

"github.com/GoogleContainerTools/kpt-functions-sdk/go/fn"
kptfilelibv1 "github.com/nephio-project/nephio/krm-functions/lib/kptfile/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -100,9 +100,10 @@ func (r *sdk) Run() (bool, error) {
kfko := r.rl.Items.GetRootKptfile()
if kfko == nil {
msg := "mandatory Kptfile is missing from the package"
fn.Log(msg)
r.rl.Results.Errorf(msg)
return false, fmt.Errorf(msg)
err := errors.New(msg)
fn.Logf("%s, error: %s\n", msg, err.Error())
r.rl.Results.Errorf("%s, error: %s\n", msg, err.Error())
return false, fmt.Errorf(err.Error(), msg)
}
r.kptfile = kptfilelibv1.KptFile{Kptfile: kfko}

Expand Down
12 changes: 6 additions & 6 deletions krm-functions/lib/nad/v1/nad.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (r *NadStruct) getNadConfig() (NadConfig, error) {
case VlanClaimOnly:
return nadConfigStruct, nil
case IpVlanType:
if nadConfigStruct.Plugins == nil || len(nadConfigStruct.Plugins) == 0 {
if len(nadConfigStruct.Plugins) == 0 {
nadConfigStruct.Plugins = []PluginCniType{
{
Capabilities: Capabilities{Ips: true},
Expand All @@ -159,7 +159,7 @@ func (r *NadStruct) getNadConfig() (NadConfig, error) {
}
return nadConfigStruct, nil
case MacVlanType:
if nadConfigStruct.Plugins == nil || len(nadConfigStruct.Plugins) == 0 {
if len(nadConfigStruct.Plugins) == 0 {
nadConfigStruct.Plugins = []PluginCniType{
{
Capabilities: Capabilities{Ips: true},
Expand All @@ -178,7 +178,7 @@ func (r *NadStruct) getNadConfig() (NadConfig, error) {
}
return nadConfigStruct, nil
case SriovType:
if nadConfigStruct.Plugins == nil || len(nadConfigStruct.Plugins) == 0 {
if len(nadConfigStruct.Plugins) == 0 {
nadConfigStruct.Plugins = []PluginCniType{
{
Capabilities: Capabilities{
Expand All @@ -193,7 +193,7 @@ func (r *NadStruct) getNadConfig() (NadConfig, error) {
}
return nadConfigStruct, nil
case VlanType:
if nadConfigStruct.Plugins == nil || len(nadConfigStruct.Plugins) == 0 {
if len(nadConfigStruct.Plugins) == 0 {
nadConfigStruct.Plugins = []PluginCniType{
{
Ipam: Ipam{
Expand All @@ -204,7 +204,7 @@ func (r *NadStruct) getNadConfig() (NadConfig, error) {
}
return nadConfigStruct, nil
case BridgeType:
if nadConfigStruct.Plugins == nil || len(nadConfigStruct.Plugins) == 0 {
if len(nadConfigStruct.Plugins) == 0 {
nadConfigStruct.Plugins = []PluginCniType{
{
Ipam: Ipam{
Expand All @@ -215,7 +215,7 @@ func (r *NadStruct) getNadConfig() (NadConfig, error) {
}
return nadConfigStruct, nil
case OtherType:
if nadConfigStruct.Plugins == nil || len(nadConfigStruct.Plugins) == 0 {
if len(nadConfigStruct.Plugins) == 0 {
nadConfigStruct.Plugins = []PluginCniType{
{
Capabilities: Capabilities{
Expand Down
3 changes: 3 additions & 0 deletions operators/focom-operator/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore build and test binaries.
bin/
28 changes: 28 additions & 0 deletions operators/focom-operator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin/*
Dockerfile.cross

# Test binary, built with `go test -c`
*.test
test-data/create-secret.sh
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Go workspace file
go.work

# Kubernetes Generated files - skip generated files, except for vendored files
!vendor/**/zz_generated.*
bin/*
testbin/*
# editor and IDE paraphernalia
.idea
.vscode
*.swp
*.swo
*~
47 changes: 47 additions & 0 deletions operators/focom-operator/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2025 The Nephio Authors.
#
# 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.

# Build the manager binary
FROM golang:1.23 AS builder
ARG TARGETOS
ARG TARGETARCH

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

# Copy the go source
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/controller/ internal/controller/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532

ENTRYPOINT ["/manager"]
Loading