istio.io/istio@v0.0.0-20240520182934-d79c90f27776/cni/pkg/plugin/plugin_cni_conformance.go (about)

     1  // Copyright Istio Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package plugin
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/containernetworking/cni/pkg/types"
    21  )
    22  
    23  // Validate k8sArgs struct works for unmarshalling kubelet args
    24  // This is important for CNI plugin conformance
    25  func TestLoadArgs(t *testing.T) {
    26  	kubeletArgs := "IgnoreUnknown=1;K8S_POD_NAMESPACE=istio-system;" +
    27  		"K8S_POD_NAME=istio-sidecar-injector-8489cf78fb-48pvg;" +
    28  		"K8S_POD_INFRA_CONTAINER_ID=3c41e946cf17a32760ff86940a73b06982f1815e9083cf2f4bfccb9b7605f326"
    29  
    30  	k8sArgs := K8sArgs{}
    31  	if err := types.LoadArgs(kubeletArgs, &k8sArgs); err != nil {
    32  		t.Fatalf("LoadArgs failed with error: %v", err)
    33  	}
    34  
    35  	if string(k8sArgs.K8S_POD_NAMESPACE) == "" || string(k8sArgs.K8S_POD_NAME) == "" {
    36  		t.Fatalf("LoadArgs didn't convert args properly, K8S_POD_NAME=\"%s\";K8S_POD_NAMESPACE=\"%s\"",
    37  			string(k8sArgs.K8S_POD_NAME), string(k8sArgs.K8S_POD_NAMESPACE))
    38  	}
    39  }