...

Source file src/k8s.io/kubernetes/pkg/kubelet/config/sources.go

Documentation: k8s.io/kubernetes/pkg/kubelet/config

     1  /*
     2  Copyright 2016 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  // Package config implements the pod configuration readers.
    18  package config
    19  
    20  import (
    21  	"sync"
    22  
    23  	"k8s.io/apimachinery/pkg/util/sets"
    24  )
    25  
    26  // SourcesReadyFn is function that returns true if the specified sources have been seen.
    27  type SourcesReadyFn func(sourcesSeen sets.String) bool
    28  
    29  // SourcesReady tracks the set of configured sources seen by the kubelet.
    30  type SourcesReady interface {
    31  	// AddSource adds the specified source to the set of sources managed.
    32  	AddSource(source string)
    33  	// AllReady returns true if the currently configured sources have all been seen.
    34  	AllReady() bool
    35  }
    36  
    37  // NewSourcesReady returns a SourcesReady with the specified function.
    38  func NewSourcesReady(sourcesReadyFn SourcesReadyFn) SourcesReady {
    39  	return &sourcesImpl{
    40  		sourcesSeen:    sets.NewString(),
    41  		sourcesReadyFn: sourcesReadyFn,
    42  	}
    43  }
    44  
    45  // sourcesImpl implements SourcesReady.  It is thread-safe.
    46  type sourcesImpl struct {
    47  	// lock protects access to sources seen.
    48  	lock sync.RWMutex
    49  	// set of sources seen.
    50  	sourcesSeen sets.String
    51  	// sourcesReady is a function that evaluates if the sources are ready.
    52  	sourcesReadyFn SourcesReadyFn
    53  }
    54  
    55  // Add adds the specified source to the set of sources managed.
    56  func (s *sourcesImpl) AddSource(source string) {
    57  	s.lock.Lock()
    58  	defer s.lock.Unlock()
    59  	s.sourcesSeen.Insert(source)
    60  }
    61  
    62  // AllReady returns true if each configured source is ready.
    63  func (s *sourcesImpl) AllReady() bool {
    64  	s.lock.RLock()
    65  	defer s.lock.RUnlock()
    66  	return s.sourcesReadyFn(s.sourcesSeen)
    67  }
    68  

View as plain text