Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into sync-0804
Browse files Browse the repository at this point in the history
  • Loading branch information
zeeke committed Aug 4, 2023
2 parents 3807a3b + 99a78b7 commit af3eeae
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 3 deletions.
1 change: 0 additions & 1 deletion api/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ func (p *SriovNetworkNodePolicy) Selected(node *corev1.Node) bool {
}
return false
}
log.Info("Selected():", "node", node.Name)
return true
}

Expand Down
4 changes: 2 additions & 2 deletions controllers/sriovnetworknodepolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ func renderDsForCR(path string, data *render.RenderData) ([]*uns.Unstructured, e

func (r *SriovNetworkNodePolicyReconciler) renderDevicePluginConfigData(ctx context.Context, pl *sriovnetworkv1.SriovNetworkNodePolicyList, node *corev1.Node) (dptypes.ResourceConfList, error) {
logger := log.Log.WithName("renderDevicePluginConfigData")
logger.Info("Start to render device plugin config data")
logger.Info("Start to render device plugin config data", "node", node.Name)
rcl := dptypes.ResourceConfList{}
for _, p := range pl.Items {
if p.Name == constants.DefaultPolicyName {
Expand Down Expand Up @@ -608,7 +608,7 @@ func (r *SriovNetworkNodePolicyReconciler) renderDevicePluginConfigData(ctx cont
return rcl, err
}
rcl.ResourceList = append(rcl.ResourceList, *rc)
logger.Info("Add resource", "Resource", *rc, "Resource list", rcl.ResourceList)
logger.Info("Add resource", "Resource", *rc)
}
}
return rcl, nil
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
netattdefv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
openshiftconfigv1 "github.com/openshift/api/config/v1"
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
"go.uber.org/zap/zapcore"
"k8s.io/apimachinery/pkg/api/errors"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
Expand Down Expand Up @@ -77,6 +78,7 @@ func main() {
"Enabling this will ensure there is only one active controller manager.")
opts := zap.Options{
Development: true,
TimeEncoder: zapcore.RFC3339NanoTimeEncoder,
}
opts.BindFlags(flag.CommandLine)
flag.Parse()
Expand Down
118 changes: 118 additions & 0 deletions test/conformance/tests/test_sriov_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,109 @@ var _ = Describe("[sriov] operator", func() {
Expect(stdout).To(ContainSubstring("2 packets transmitted, 2 received, 0% packet loss"))
})
})

Context("ExcludeTopology", func() {

var excludeTopologyTrueResourceXXX, excludeTopologyFalseResourceXXX, excludeTopologyFalseResourceYYY *sriovv1.SriovNetworkNodePolicy
var node string
var intf *sriovv1.InterfaceExt

BeforeEach(func() {
if discovery.Enabled() {
Skip("Test unsuitable to be run in discovery mode")
}

node = sriovInfos.Nodes[0]
sriovDeviceList, err := sriovInfos.FindSriovDevices(node)
Expect(err).ToNot(HaveOccurred())
unusedSriovDevices, err := findUnusedSriovDevices(node, sriovDeviceList)
Expect(err).ToNot(HaveOccurred())

intf = unusedSriovDevices[0]

excludeTopologyTrueResourceXXX = &sriovv1.SriovNetworkNodePolicy{
ObjectMeta: metav1.ObjectMeta{
Name: "test-exclude-topology-true-res-xxx",
Namespace: operatorNamespace,
},

Spec: sriovv1.SriovNetworkNodePolicySpec{
NumVfs: 10,
ResourceName: "resourceXXX",
NodeSelector: map[string]string{"kubernetes.io/hostname": node},
NicSelector: sriovv1.SriovNetworkNicSelector{
PfNames: []string{intf.Name + "#0-4"},
},
ExcludeTopology: true,
},
}

excludeTopologyFalseResourceXXX = &sriovv1.SriovNetworkNodePolicy{
ObjectMeta: metav1.ObjectMeta{
Name: "test-exclude-topology-false-res-xxx",
Namespace: operatorNamespace,
},

Spec: sriovv1.SriovNetworkNodePolicySpec{
NumVfs: 10,
ResourceName: "resourceXXX",
NodeSelector: map[string]string{"kubernetes.io/hostname": node},
NicSelector: sriovv1.SriovNetworkNicSelector{
PfNames: []string{intf.Name + "#5-9"},
},
ExcludeTopology: false,
},
}

excludeTopologyFalseResourceYYY = &sriovv1.SriovNetworkNodePolicy{
ObjectMeta: metav1.ObjectMeta{
Name: "test-exclude-topology-false-res-yyy",
Namespace: operatorNamespace,
},

Spec: sriovv1.SriovNetworkNodePolicySpec{
NumVfs: 10,
ResourceName: "resourceYYY",
NodeSelector: map[string]string{"kubernetes.io/hostname": node},
NicSelector: sriovv1.SriovNetworkNicSelector{
PfNames: []string{intf.Name + "#5-9"},
},
ExcludeTopology: false,
},
}

})

It("field is forwarded to the device plugin configuration", func() {

err := clients.Create(context.Background(), excludeTopologyTrueResourceXXX)
Expect(err).ToNot(HaveOccurred())

assertDevicePluginConfigurationContains(node,
fmt.Sprintf(`{"resourceName":"resourceXXX","excludeTopology":true,"selectors":{"pfNames":["%s#0-4"],"IsRdma":false,"NeedVhostNet":false},"SelectorObj":null}`, intf.Name))

err = clients.Create(context.Background(), excludeTopologyFalseResourceYYY)
Expect(err).ToNot(HaveOccurred())

assertDevicePluginConfigurationContains(node,
fmt.Sprintf(`{"resourceName":"resourceXXX","excludeTopology":true,"selectors":{"pfNames":["%s#0-4"],"IsRdma":false,"NeedVhostNet":false},"SelectorObj":null}`, intf.Name))
assertDevicePluginConfigurationContains(node,
fmt.Sprintf(`{"resourceName":"resourceYYY","selectors":{"pfNames":["%s#5-9"],"IsRdma":false,"NeedVhostNet":false},"SelectorObj":null}`, intf.Name))
})

It("multiple values for the same resource should not be allowed", func() {

err := clients.Create(context.Background(), excludeTopologyTrueResourceXXX)
Expect(err).ToNot(HaveOccurred())

err = clients.Create(context.Background(), excludeTopologyFalseResourceXXX)
Expect(err).To(HaveOccurred())

Expect(err.Error()).To(ContainSubstring(
"excludeTopology[false] field conflicts with policy [test-exclude-topology-true-res-xxx].ExcludeTopology[true]" +
" as they target the same resource[resourceXXX]"))
})
})
})

Context("Nic Validation", func() {
Expand Down Expand Up @@ -2127,3 +2230,18 @@ func assertObjectIsNotFound(name string, obj runtimeclient.Object) {
return err != nil && k8serrors.IsNotFound(err)
}, 2*time.Minute, 10*time.Second).Should(BeTrue())
}

func assertDevicePluginConfigurationContains(node, configuration string) {
Eventually(func(g Gomega) map[string]string {
cfg := corev1.ConfigMap{}
err := clients.Get(context.Background(), runtimeclient.ObjectKey{
Name: "device-plugin-config",
Namespace: operatorNamespace,
}, &cfg)
g.Expect(err).ToNot(HaveOccurred())

return cfg.Data
}, 30*time.Second, 2*time.Second).Should(
HaveKeyWithValue(node, ContainSubstring(configuration)),
)
}
2 changes: 2 additions & 0 deletions test/util/client/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func New(kubeconfig string) *ClientSet {
config, err = rest.InClusterConfig()
}
if err != nil {
glog.Warningf("Error while building client config: %v", err)
return nil
}

Expand All @@ -74,6 +75,7 @@ func New(kubeconfig string) *ClientSet {
Scheme: crScheme,
})
if err != nil {
glog.Warningf("Error while creating ClientSet: %v", err)
return nil
}
return clientSet
Expand Down

0 comments on commit af3eeae

Please sign in to comment.