Fixed the lease endpoint reconciler creation of kubernetes endpoint and lease file ttl

This commit is contained in:
Robert Rati 2017-10-11 18:58:41 -04:00
parent 78ada62c30
commit 099404a0ee
2 changed files with 7 additions and 6 deletions

View File

@ -93,8 +93,6 @@ const (
DefaultEndpointReconcilerInterval = 10 * time.Second DefaultEndpointReconcilerInterval = 10 * time.Second
// DefaultEndpointReconcilerTTL is the default TTL timeout for the storage layer // DefaultEndpointReconcilerTTL is the default TTL timeout for the storage layer
DefaultEndpointReconcilerTTL = 15 * time.Second DefaultEndpointReconcilerTTL = 15 * time.Second
// DefaultStorageEndpoint is the default storage endpoint for the lease controller
DefaultStorageEndpoint = "kube-apiserver-endpoint"
) )
type ExtraConfig struct { type ExtraConfig struct {
@ -206,7 +204,7 @@ func (c *Config) createLeaseReconciler() reconcilers.EndpointReconciler {
if err != nil { if err != nil {
glog.Fatalf("Error creating storage factory: %v", err) glog.Fatalf("Error creating storage factory: %v", err)
} }
endpointConfig, err := c.ExtraConfig.StorageFactory.NewConfig(kapi.Resource(DefaultStorageEndpoint)) endpointConfig, err := c.ExtraConfig.StorageFactory.NewConfig(kapi.Resource("endpoints"))
if err != nil { if err != nil {
glog.Fatalf("Error getting storage config: %v", err) glog.Fatalf("Error getting storage config: %v", err)
} }
@ -214,7 +212,7 @@ func (c *Config) createLeaseReconciler() reconcilers.EndpointReconciler {
StorageConfig: endpointConfig, StorageConfig: endpointConfig,
Decorator: generic.UndecoratedStorage, Decorator: generic.UndecoratedStorage,
DeleteCollectionWorkers: 0, DeleteCollectionWorkers: 0,
ResourcePrefix: c.ExtraConfig.StorageFactory.ResourcePrefix(kapi.Resource(DefaultStorageEndpoint)), ResourcePrefix: c.ExtraConfig.StorageFactory.ResourcePrefix(kapi.Resource("endpoints")),
}) })
endpointRegistry := endpoint.NewRegistry(endpointsStorage) endpointRegistry := endpoint.NewRegistry(endpointsStorage)
masterLeases := reconcilers.NewLeases(leaseStorage, "/masterleases/", ttl) masterLeases := reconcilers.NewLeases(leaseStorage, "/masterleases/", ttl)

View File

@ -24,6 +24,7 @@ https://github.com/openshift/origin/blob/bb340c5dd5ff72718be86fb194dedc0faed7f4c
import ( import (
"fmt" "fmt"
"net" "net"
"path"
"sync" "sync"
"time" "time"
@ -77,7 +78,8 @@ func (s *storageLeases) ListLeases() ([]string, error) {
// UpdateLease resets the TTL on a master IP in storage // UpdateLease resets the TTL on a master IP in storage
func (s *storageLeases) UpdateLease(ip string) error { func (s *storageLeases) UpdateLease(ip string) error {
return s.storage.GuaranteedUpdate(apirequest.NewDefaultContext(), s.baseKey+"/"+ip, &api.Endpoints{}, true, nil, func(input kruntime.Object, respMeta storage.ResponseMeta) (kruntime.Object, *uint64, error) { key := path.Join(s.baseKey, ip)
return s.storage.GuaranteedUpdate(apirequest.NewDefaultContext(), key, &api.Endpoints{}, true, nil, func(input kruntime.Object, respMeta storage.ResponseMeta) (kruntime.Object, *uint64, error) {
// just make sure we've got the right IP set, and then refresh the TTL // just make sure we've got the right IP set, and then refresh the TTL
existing := input.(*api.Endpoints) existing := input.(*api.Endpoints)
existing.Subsets = []api.EndpointSubset{ existing.Subsets = []api.EndpointSubset{
@ -86,7 +88,8 @@ func (s *storageLeases) UpdateLease(ip string) error {
}, },
} }
leaseTime := uint64(s.leaseTime) // leaseTime needs to be in seconds
leaseTime := uint64(s.leaseTime / time.Second)
// NB: GuaranteedUpdate does not perform the store operation unless // NB: GuaranteedUpdate does not perform the store operation unless
// something changed between load and store (not including resource // something changed between load and store (not including resource