Skip to content

Commit

Permalink
Revert "Downward api node defaults"
Browse files Browse the repository at this point in the history
  • Loading branch information
piosz authored Jun 15, 2016
1 parent 3d09b99 commit 51af487
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 363 deletions.
119 changes: 0 additions & 119 deletions pkg/fieldpath/fieldpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/assert"

"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
)

func TestExtractFieldPathAsString(t *testing.T) {
Expand Down Expand Up @@ -118,119 +115,3 @@ func TestExtractFieldPathAsString(t *testing.T) {
}
}
}

func getPod(cname, cpuRequest, cpuLimit, memoryRequest, memoryLimit string) *api.Pod {
resources := api.ResourceRequirements{
Limits: make(api.ResourceList),
Requests: make(api.ResourceList),
}
if cpuLimit != "" {
resources.Limits[api.ResourceCPU] = resource.MustParse(cpuLimit)
}
if memoryLimit != "" {
resources.Limits[api.ResourceMemory] = resource.MustParse(memoryLimit)
}
if cpuRequest != "" {
resources.Requests[api.ResourceCPU] = resource.MustParse(cpuRequest)
}
if memoryRequest != "" {
resources.Requests[api.ResourceMemory] = resource.MustParse(memoryRequest)
}
return &api.Pod{
Spec: api.PodSpec{
Containers: []api.Container{
{
Name: cname,
Resources: resources,
},
},
},
}
}

func TestExtractResourceValue(t *testing.T) {
cases := []struct {
fs *api.ResourceFieldSelector
pod *api.Pod
cName string
expectedValue string
expectedError error
}{
{
fs: &api.ResourceFieldSelector{
Resource: "limits.cpu",
},
cName: "foo",
pod: getPod("foo", "", "9", "", ""),
expectedValue: "9",
},
{
fs: &api.ResourceFieldSelector{
Resource: "requests.cpu",
},
cName: "foo",
pod: getPod("foo", "", "", "", ""),
expectedValue: "0",
},
{
fs: &api.ResourceFieldSelector{
Resource: "requests.cpu",
},
cName: "foo",
pod: getPod("foo", "8", "", "", ""),
expectedValue: "8",
},
{
fs: &api.ResourceFieldSelector{
Resource: "requests.cpu",
},
cName: "foo",
pod: getPod("foo", "100m", "", "", ""),
expectedValue: "1",
},
{
fs: &api.ResourceFieldSelector{
Resource: "requests.cpu",
Divisor: resource.MustParse("100m"),
},
cName: "foo",
pod: getPod("foo", "1200m", "", "", ""),
expectedValue: "12",
},
{
fs: &api.ResourceFieldSelector{
Resource: "requests.memory",
},
cName: "foo",
pod: getPod("foo", "", "", "100Mi", ""),
expectedValue: "104857600",
},
{
fs: &api.ResourceFieldSelector{
Resource: "requests.memory",
Divisor: resource.MustParse("1Mi"),
},
cName: "foo",
pod: getPod("foo", "", "", "100Mi", "1Gi"),
expectedValue: "100",
},
{
fs: &api.ResourceFieldSelector{
Resource: "limits.memory",
},
cName: "foo",
pod: getPod("foo", "", "", "10Mi", "100Mi"),
expectedValue: "104857600",
},
}
as := assert.New(t)
for idx, tc := range cases {
actual, err := ExtractResourceValueByContainerName(tc.fs, tc.pod, tc.cName)
if tc.expectedError != nil {
as.Equal(tc.expectedError, err, "expected test case [%d] to fail with error %v; got %v", idx, tc.expectedError, err)
} else {
as.Nil(err, "expected test case [%d] to not return an error; got %v", idx, err)
as.Equal(tc.expectedValue, actual, "expected test case [%d] to return %q; got %q instead", idx, tc.expectedValue, actual)
}
}
}
24 changes: 2 additions & 22 deletions pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,9 +831,6 @@ type Kubelet struct {
// should manage attachment/detachment of volumes scheduled to this node,
// and disable kubelet from executing any attach/detach operations
enableControllerAttachDetach bool

// lastUpdatedNodeObject is a cached version of the node as last reported back to the api server.
lastUpdatedNodeObject atomic.Value
}

// Validate given node IP belongs to the current host
Expand Down Expand Up @@ -1146,10 +1143,6 @@ func (kl *Kubelet) registerWithApiserver() {
glog.Errorf("Unable to construct api.Node object for kubelet: %v", err)
continue
}

// Cache the node object.
kl.lastUpdatedNodeObject.Store(node)

glog.V(2).Infof("Attempting to register node %s", node.Name)
if _, err := kl.kubeClient.Core().Nodes().Create(node); err != nil {
if !apierrors.IsAlreadyExists(err) {
Expand Down Expand Up @@ -1561,11 +1554,7 @@ func (kl *Kubelet) makeEnvironmentVariables(pod *api.Pod, container *api.Contain
return result, err
}
case envVar.ValueFrom.ResourceFieldRef != nil:
defaultedPod, defaultedContainer, err := kl.defaultPodLimitsForDownwardApi(pod, container)
if err != nil {
return result, err
}
runtimeVal, err = containerResourceRuntimeValue(envVar.ValueFrom.ResourceFieldRef, defaultedPod, defaultedContainer)
runtimeVal, err = containerResourceRuntimeValue(envVar.ValueFrom.ResourceFieldRef, pod, container)
if err != nil {
return result, err
}
Expand Down Expand Up @@ -1905,12 +1894,7 @@ func (kl *Kubelet) syncPod(o syncPodOptions) error {
}

// Mount volumes and update the volume manager
// Default limits for containers here to have downward API expose user-friendly limits to pods.
defaultedPod, _, err := kl.defaultPodLimitsForDownwardApi(pod, nil)
if err != nil {
return err
}
podVolumes, err := kl.mountExternalVolumes(defaultedPod)
podVolumes, err := kl.mountExternalVolumes(pod)
if err != nil {
ref, errGetRef := api.GetReference(pod)
if errGetRef == nil && ref != nil {
Expand Down Expand Up @@ -3523,10 +3507,6 @@ func (kl *Kubelet) tryUpdateNodeStatus() error {
}
// Update the current status on the API server
_, err = kl.kubeClient.Core().Nodes().UpdateStatus(node)
if err == nil {
// store recently updated node information.
kl.lastUpdatedNodeObject.Store(node)
}
return err
}

Expand Down
84 changes: 0 additions & 84 deletions pkg/kubelet/kubelet_resources.go

This file was deleted.

89 changes: 0 additions & 89 deletions pkg/kubelet/kubelet_resources_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/kubelet/kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func newTestKubeletWithImageList(t *testing.T, imageList []kubecontainer.Image)
}
kubelet.evictionManager = evictionManager
kubelet.AddPodAdmitHandler(evictionAdmitHandler)
kubelet.lastUpdatedNodeObject.Store(&api.Node{})

return &TestKubelet{kubelet, fakeRuntime, mockCadvisor, fakeKubeClient, fakeMirrorClient, fakeClock, nil}
}

Expand Down
Loading

0 comments on commit 51af487

Please sign in to comment.