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

Spec pointer to have better support for omit empty #7

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
4 changes: 0 additions & 4 deletions config/crd/bases/req.nephio.org_capacities.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ spec:
throughput
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
maxNFConnections:
description: MaxNFConnections defines the max NF(s) that can be connected
to this NF/device
type: integer
maxSessions:
description: MaxSessions defines the max sessions of the control plane
expressed in unit of 1000s
Expand Down
4 changes: 0 additions & 4 deletions config/crd/bases/workload.nephio.org_amfdeployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ spec:
throughput
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
maxNFConnections:
description: MaxNFConnections defines the max NF(s) that can be
connected to this NF/device
type: integer
maxSessions:
description: MaxSessions defines the max sessions of the control
plane expressed in unit of 1000s
Expand Down
4 changes: 0 additions & 4 deletions config/crd/bases/workload.nephio.org_smfdeployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ spec:
throughput
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
maxNFConnections:
description: MaxNFConnections defines the max NF(s) that can be
connected to this NF/device
type: integer
maxSessions:
description: MaxSessions defines the max sessions of the control
plane expressed in unit of 1000s
Expand Down
4 changes: 0 additions & 4 deletions config/crd/bases/workload.nephio.org_upfdeployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ spec:
throughput
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
maxNFConnections:
description: MaxNFConnections defines the max NF(s) that can be
connected to this NF/device
type: integer
maxSessions:
description: MaxSessions defines the max sessions of the control
plane expressed in unit of 1000s
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ go 1.20
require (
github.com/google/go-cmp v0.5.9
github.com/nokia/k8s-ipam v0.0.4-0.20230416191338-dcd944a8d636
github.com/stretchr/testify v1.8.1
k8s.io/api v0.27.1
k8s.io/apimachinery v0.27.1
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2
sigs.k8s.io/controller-runtime v0.14.6
)

Expand Down Expand Up @@ -35,7 +35,6 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.15.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
Expand All @@ -57,7 +56,6 @@ require (
k8s.io/client-go v0.27.1 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-openapi v0.0.0-20230327201221-f5883ff37f0c // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion hack/boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Nephio.
Copyright 2023 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 Down
18 changes: 18 additions & 0 deletions lcov.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
mode: set
github.com/nephio-project/api/nf_requirements/v1alpha1/capacity_interfaces.go:22.63,24.2 1 1
github.com/nephio-project/api/nf_requirements/v1alpha1/capacity_interfaces.go:27.65,29.2 1 1
github.com/nephio-project/api/nf_requirements/v1alpha1/capacity_interfaces.go:32.41,34.2 1 0
github.com/nephio-project/api/nf_requirements/v1alpha1/capacity_interfaces.go:37.44,39.2 1 0
github.com/nephio-project/api/nf_requirements/v1alpha1/dnn_interfaces.go:24.65,26.35 2 1
github.com/nephio-project/api/nf_requirements/v1alpha1/dnn_interfaces.go:26.35,29.3 2 1
github.com/nephio-project/api/nf_requirements/v1alpha1/dnn_interfaces.go:30.2,30.12 1 1
github.com/nephio-project/api/nf_requirements/v1alpha1/dnn_interfaces.go:34.42,35.25 1 1
github.com/nephio-project/api/nf_requirements/v1alpha1/dnn_interfaces.go:35.25,37.3 1 1
github.com/nephio-project/api/nf_requirements/v1alpha1/dnn_interfaces.go:38.2,38.21 1 1
github.com/nephio-project/api/nf_requirements/v1alpha1/dnn_interfaces.go:42.33,44.2 1 1
github.com/nephio-project/api/nf_requirements/v1alpha1/dnn_interfaces.go:47.40,49.2 1 1
github.com/nephio-project/api/nf_requirements/v1alpha1/interface_interfaces.go:43.63,45.35 2 1
github.com/nephio-project/api/nf_requirements/v1alpha1/interface_interfaces.go:45.35,48.3 2 1
github.com/nephio-project/api/nf_requirements/v1alpha1/interface_interfaces.go:49.2,49.12 1 1
github.com/nephio-project/api/nf_requirements/v1alpha1/interface_interfaces.go:53.42,55.2 1 1
github.com/nephio-project/api/nf_requirements/v1alpha1/interface_interfaces.go:58.56,60.2 1 1
2 changes: 1 addition & 1 deletion nf_deployments/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions nf_requirements/v1alpha1/capacity_interfaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright 2023 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.
*/

package v1alpha1

import "k8s.io/apimachinery/pkg/api/resource"

// GetMaxUplinkThroughput return the max uplinkthroughput
func (r *Capacity) GetMaxUplinkThroughput() *resource.Quantity {
return r.Spec.MaxUplinkThroughput
}

// GetMaxDownlinkThroughput return the max downlinkthroughput
func (r *Capacity) GetMaxDownlinkThroughput() *resource.Quantity {
return r.Spec.MaxDownlinkThroughput
}

// GetMaxSessions returns the max sessions
func (r *Capacity) GetMaxSessions() *int {
return r.Spec.MaxSessions
}

// GetMaxSubscribers returns the max subscribers
func (r *Capacity) GetMaxSubscribers() *int {
return r.Spec.MaxSubscribers
}
192 changes: 192 additions & 0 deletions nf_requirements/v1alpha1/capacity_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/*
Copyright 2023 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.
*/

package v1alpha1

import (
"testing"

"github.com/google/go-cmp/cmp"
"k8s.io/apimachinery/pkg/api/resource"
)

func TestCapacityGetMaxUplinkThroughput(t *testing.T) {
res := resource.MustParse("5G")

tests := map[string]struct {
input Capacity
want *resource.Quantity
}{
"TestGetMaxUplinkThroughputEmpty": {
input: Capacity{
Spec: CapacitySpec{},
},
want: nil,
},
"TestGetMaxUplinkThroughput": {
input: Capacity{
Spec: CapacitySpec{
MaxUplinkThroughput: &res,
},
},
want: &res,
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
got := tc.input.GetMaxUplinkThroughput()
switch {
case got == nil && tc.want != nil:
t.Errorf("TestCapacityGetMaxUplinkThroughput: -want %v, +got: nil\n", *tc.want)
case got != nil && tc.want == nil:
t.Errorf("TestCapacityGetMaxUplinkThroughput: -want nil, +got: %v\n", *got)
case got != nil && tc.want != nil:
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("TestCapacityGetMaxUplinkThroughput: -want, +got:\n%s", diff)
}
default:
// got == nil and want == nil ok
}
})
}
}

func TestCapacityGetMaxDownlinkThroughput(t *testing.T) {
res := resource.MustParse("5G")

tests := map[string]struct {
input Capacity
want *resource.Quantity
}{
"TestGetMaxDownlinkThroughputEmpty": {
input: Capacity{
Spec: CapacitySpec{},
},
want: nil,
},
"TestGetMaxDownlinkThroughput": {
input: Capacity{
Spec: CapacitySpec{
MaxDownlinkThroughput: &res,
},
},
want: &res,
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
got := tc.input.GetMaxDownlinkThroughput()
switch {
case got == nil && tc.want != nil:
t.Errorf("TestCapacityGetMaxDownlinkThroughput: -want %v, +got: nil\n", *tc.want)
case got != nil && tc.want == nil:
t.Errorf("TestCapacityGetMaxDownlinkThroughput: -want nil, +got: %v\n", *got)
case got != nil && tc.want != nil:
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("TestCapacityGetMaxDownlinkThroughput: -want, +got:\n%s", diff)
}
default:
// got == nil and want == nil ok
}
})
}
}

func TestCapacityGetMaxSessions(t *testing.T) {
maxSessions := 10

tests := map[string]struct {
input Capacity
want *int
}{
"TestGetMaxSessionsEmpty": {
input: Capacity{
Spec: CapacitySpec{},
},
want: nil,
},
"TestGetMaxSessions": {
input: Capacity{
Spec: CapacitySpec{
MaxSessions: &maxSessions,
},
},
want: &maxSessions,
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
got := tc.input.GetMaxSessions()
switch {
case got == nil && tc.want != nil:
t.Errorf("TestCapacityGetMaxSessions: -want %v, +got: nil\n", *tc.want)
case got != nil && tc.want == nil:
t.Errorf("TestCapacityGetMaxSessions: -want nil, +got: %v\n", *got)
case got != nil && tc.want != nil:
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("TestCapacityGetMaxSessions: -want, +got:\n%s", diff)
}
default:
// got == nil and want == nil ok
}
})
}
}

func TestCapacityGetMaxSubscribers(t *testing.T) {
maxSubscribers := 10

tests := map[string]struct {
input Capacity
want *int
}{
"TestGetMaxSubscribersEmpty": {
input: Capacity{
Spec: CapacitySpec{},
},
want: nil,
},
"TestGetMaxSubscribers": {
input: Capacity{
Spec: CapacitySpec{
MaxSubscribers: &maxSubscribers,
},
},
want: &maxSubscribers,
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
got := tc.input.GetMaxSubscribers()
switch {
case got == nil && tc.want != nil:
t.Errorf("TestCapacityGetMaxSubscribers: -want %v, +got: nil\n", *tc.want)
case got != nil && tc.want == nil:
t.Errorf("TestCapacityGetMaxSubscribers: -want nil, +got: %v\n", *got)
case got != nil && tc.want != nil:
if diff := cmp.Diff(tc.want, got); diff != "" {
t.Errorf("TestCapacityGetMaxSubscribers: -want, +got:\n%s", diff)
}
default:
// got == nil and want == nil ok
}
})
}
}
14 changes: 8 additions & 6 deletions nf_requirements/v1alpha1/capacity_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ type Capacity struct {

type CapacitySpec struct {
// MaxUplinkThroughput defines the max uplink dataplane throughput
MaxUplinkThroughput resource.Quantity `json:"maxUplinkThroughput,omitempty" yaml:"maxUplinkThroughput,omitempty"`
// +kubebuilder:validation:Optional
MaxUplinkThroughput *resource.Quantity `json:"maxUplinkThroughput,omitempty" yaml:"maxUplinkThroughput,omitempty"`
// MaxDownlinkThroughput defines the max downlink dataplane throughput
MaxDownlinkThroughput resource.Quantity `json:"maxDownlinkThroughput,omitempty" yaml:"maxDownlinkThroughput,omitempty"`
// +kubebuilder:validation:Optional
MaxDownlinkThroughput *resource.Quantity `json:"maxDownlinkThroughput,omitempty" yaml:"maxDownlinkThroughput,omitempty"`
// MaxSessions defines the max sessions of the control plane
// expressed in unit of 1000s
MaxSessions int `json:"maxSessions,omitempty" yaml:"maxSessions,omitempty"`
// +kubebuilder:validation:Optional
MaxSessions *int `json:"maxSessions,omitempty" yaml:"maxSessions,omitempty"`
// MaxSubscribers defines the max subscribers
// expressed in unit of 1000s
MaxSubscribers int `json:"maxSubscribers,omitempty" yaml:"maxSubscribers,omitempty"`
// MaxNFConnections defines the max NF(s) that can be connected to this NF/device
MaxNFConnections uint16 `json:"maxNFConnections,omitempty" yaml:"maxNFConnections,omitempty"`
henderiw marked this conversation as resolved.
Show resolved Hide resolved
// +kubebuilder:validation:Optional
MaxSubscribers *int `json:"maxSubscribers,omitempty" yaml:"maxSubscribers,omitempty"`
}

type CapacityStatus struct {
Expand Down
Loading