kubernetes container_hash_test 源码

  • 2022-09-18
  • 浏览 (238)

kubernetes container_hash_test 代码

文件路径:/pkg/kubelet/container/container_hash_test.go

/*
Copyright 2019 The Kubernetes 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 container

import (
	"encoding/json"
	"testing"

	"k8s.io/api/core/v1"
)

var (
	sampleContainer = `
{
  "name": "test_container",
  "image": "foo/image:v1",
  "command": [
    "/bin/testcmd"
  ],
  "args": [
    "/bin/sh",
    "-c",
    "echo abc"
  ],
  "ports": [
    {
      "containerPort": 8001
    }
  ],
  "env": [
    {
      "name": "ENV_FOO",
      "value": "bar"
    },
    {
      "name": "ENV_BAR",
      "valueFrom": {
        "secretKeyRef": {
          "name": "foo",
          "key": "bar",
          "optional": true
        }
      }
    }
  ],
  "resources": {
    "limits": {
      "foo": "1G"
    },
    "requests": {
      "foo": "500M"
    }
  }
}
`

	sampleV115HashValue = uint64(0x311670a)
	sampleV116HashValue = sampleV115HashValue
)

func TestConsistentHashContainer(t *testing.T) {
	container := &v1.Container{}
	if err := json.Unmarshal([]byte(sampleContainer), container); err != nil {
		t.Error(err)
	}

	currentHash := HashContainer(container)
	if currentHash != sampleV116HashValue {
		t.Errorf("mismatched hash value with v1.16")
	}

	if currentHash != sampleV115HashValue {
		t.Errorf("mismatched hash value with v1.15")
	}
}

相关信息

kubernetes 源码目录

相关文章

kubernetes cache 源码

kubernetes cache_test 源码

kubernetes container_gc 源码

kubernetes helpers 源码

kubernetes helpers_test 源码

kubernetes os 源码

kubernetes ref 源码

kubernetes ref_test 源码

kubernetes resize 源码

kubernetes runtime 源码

0  赞