Skip to content

Commit 5a4406c

Browse files
committed
Integrate depreacted K8s functions
1 parent 30b8fa0 commit 5a4406c

10 files changed

+1385
-3
lines changed

network/bandwidth/fake_shaper.go

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Copyright 2015 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package bandwidth
18+
19+
import (
20+
"errors"
21+
22+
"k8s.io/apimachinery/pkg/api/resource"
23+
)
24+
25+
// FakeShaper provides an implementation of the bandwidth.Shaper.
26+
// Beware this is implementation has no features besides Reset and GetCIDRs.
27+
type FakeShaper struct {
28+
CIDRs []string
29+
ResetCIDRs []string
30+
}
31+
32+
// Limit is not implemented
33+
func (f *FakeShaper) Limit(cidr string, egress, ingress *resource.Quantity) error {
34+
return errors.New("unimplemented")
35+
}
36+
37+
// Reset appends a particular CIDR to the set of ResetCIDRs being managed by this shaper
38+
func (f *FakeShaper) Reset(cidr string) error {
39+
f.ResetCIDRs = append(f.ResetCIDRs, cidr)
40+
return nil
41+
}
42+
43+
// ReconcileInterface is not implemented
44+
func (f *FakeShaper) ReconcileInterface() error {
45+
return errors.New("unimplemented")
46+
}
47+
48+
// ReconcileCIDR is not implemented
49+
func (f *FakeShaper) ReconcileCIDR(cidr string, egress, ingress *resource.Quantity) error {
50+
return errors.New("unimplemented")
51+
}
52+
53+
// GetCIDRs returns the set of CIDRs that are being managed by this shaper
54+
func (f *FakeShaper) GetCIDRs() ([]string, error) {
55+
return f.CIDRs, nil
56+
}

network/bandwidth/interfaces.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright 2015 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package bandwidth
18+
19+
import "k8s.io/apimachinery/pkg/api/resource"
20+
21+
// Shaper is designed so that the shaper structs created
22+
// satisfy the Shaper interface.
23+
type Shaper interface {
24+
// Limit the bandwidth for a particular CIDR on a particular interface
25+
// * ingress and egress are in bits/second
26+
// * cidr is expected to be a valid network CIDR (e.g. '1.2.3.4/32' or '10.20.0.1/16')
27+
// 'egress' bandwidth limit applies to all packets on the interface whose source matches 'cidr'
28+
// 'ingress' bandwidth limit applies to all packets on the interface whose destination matches 'cidr'
29+
// Limits are aggregate limits for the CIDR, not per IP address. CIDRs must be unique, but can be overlapping, traffic
30+
// that matches multiple CIDRs counts against all limits.
31+
Limit(cidr string, egress, ingress *resource.Quantity) error
32+
// Remove a bandwidth limit for a particular CIDR on a particular network interface
33+
Reset(cidr string) error
34+
// Reconcile the interface managed by this shaper with the state on the ground.
35+
ReconcileInterface() error
36+
// Reconcile a CIDR managed by this shaper with the state on the ground
37+
ReconcileCIDR(cidr string, egress, ingress *resource.Quantity) error
38+
// GetCIDRs returns the set of CIDRs that are being managed by this shaper
39+
GetCIDRs() ([]string, error)
40+
}

0 commit comments

Comments
 (0)