...

Source file src/k8s.io/kubernetes/pkg/kubelet/secret/fake_manager.go

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

     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 secret
    18  
    19  import (
    20  	"fmt"
    21  
    22  	v1 "k8s.io/api/core/v1"
    23  )
    24  
    25  // fakeManager implements Manager interface for testing purposes.
    26  // simple operations to apiserver.
    27  type fakeManager struct {
    28  	secrets []*v1.Secret
    29  }
    30  
    31  // NewFakeManager creates empty/fake secret manager
    32  func NewFakeManager() Manager {
    33  	return &fakeManager{}
    34  }
    35  
    36  // NewFakeManagerWithSecrets creates a fake secret manager with the provided secrets
    37  func NewFakeManagerWithSecrets(secrets []*v1.Secret) Manager {
    38  	return &fakeManager{
    39  		secrets: secrets,
    40  	}
    41  }
    42  
    43  // GetSecret function returns the searched secret if it was provided during the manager initialization, otherwise, it returns an error.
    44  // If the manager was initialized without any secrets, it returns a nil secret."
    45  func (s *fakeManager) GetSecret(namespace, name string) (*v1.Secret, error) {
    46  	if s.secrets == nil {
    47  		return nil, nil
    48  	}
    49  
    50  	for _, secret := range s.secrets {
    51  		if secret.Name == name {
    52  			return secret, nil
    53  		}
    54  	}
    55  
    56  	return nil, fmt.Errorf("secret %s not found", name)
    57  }
    58  
    59  // RegisterPod implements the RegisterPod method for testing purposes.
    60  func (s *fakeManager) RegisterPod(pod *v1.Pod) {
    61  }
    62  
    63  // UnregisterPod implements the UnregisterPod method for testing purposes.
    64  func (s *fakeManager) UnregisterPod(pod *v1.Pod) {
    65  }
    66  

View as plain text