mirror of https://github.com/kubernetes/kops.git
Merge pull request #15662 from johngmyers/vfscontext-2
More VFSContext refactoring
This commit is contained in:
commit
aff52d8366
|
|
@ -141,7 +141,7 @@ func RunCreate(ctx context.Context, f *util.Factory, out io.Writer, c *CreateOpt
|
|||
|
||||
// Adding a PerformAssignments() call here as the user might be trying to use
|
||||
// the new `-f` feature, with an old cluster definition.
|
||||
err = cloudup.PerformAssignments(v, cloud)
|
||||
err = cloudup.PerformAssignments(v, vfsContext, cloud)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error populating configuration: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -645,13 +645,13 @@ func RunCreateCluster(ctx context.Context, f *util.Factory, out io.Writer, c *Cr
|
|||
return err
|
||||
}
|
||||
|
||||
err = cloudup.PerformAssignments(cluster, cloud)
|
||||
err = cloudup.PerformAssignments(cluster, clientset.VFSContext(), cloud)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error populating configuration: %v", err)
|
||||
}
|
||||
|
||||
strict := false
|
||||
err = validation.DeepValidate(cluster, instanceGroups, strict, nil)
|
||||
err = validation.DeepValidate(cluster, instanceGroups, strict, clientset.VFSContext(), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -691,7 +691,7 @@ func RunCreateCluster(ctx context.Context, f *util.Factory, out io.Writer, c *Cr
|
|||
fullInstanceGroups = append(fullInstanceGroups, fullGroup)
|
||||
}
|
||||
|
||||
err = validation.DeepValidate(fullCluster, fullInstanceGroups, true, nil)
|
||||
err = validation.DeepValidate(fullCluster, fullInstanceGroups, true, clientset.VFSContext(), nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("validation of the full cluster and instance group specs failed: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ func RunCreateInstanceGroup(ctx context.Context, f *util.Factory, out io.Writer,
|
|||
return err
|
||||
}
|
||||
|
||||
channel, err := cloudup.ChannelForCluster(cluster)
|
||||
channel, err := cloudup.ChannelForCluster(clientset.VFSContext(), cluster)
|
||||
if err != nil {
|
||||
klog.Warningf("%v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ func updateCluster(ctx context.Context, clientset simple.Clientset, oldCluster,
|
|||
return "", err
|
||||
}
|
||||
|
||||
err = cloudup.PerformAssignments(newCluster, cloud)
|
||||
err = cloudup.PerformAssignments(newCluster, clientset.VFSContext(), cloud)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error populating configuration: %v", err)
|
||||
}
|
||||
|
|
@ -266,7 +266,7 @@ func updateCluster(ctx context.Context, clientset simple.Clientset, oldCluster,
|
|||
return fmt.Sprintf("error populating cluster spec: %s", err), nil
|
||||
}
|
||||
|
||||
err = validation.DeepValidate(fullCluster, instanceGroups, true, cloud)
|
||||
err = validation.DeepValidate(fullCluster, instanceGroups, true, clientset.VFSContext(), cloud)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("validation failed: %s", err), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,16 +127,16 @@ func RunEditInstanceGroup(ctx context.Context, f *util.Factory, out io.Writer, o
|
|||
return err
|
||||
}
|
||||
|
||||
channel, err := cloudup.ChannelForCluster(cluster)
|
||||
if err != nil {
|
||||
klog.Warningf("%v", err)
|
||||
}
|
||||
|
||||
clientset, err := f.KopsClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
channel, err := cloudup.ChannelForCluster(clientset.VFSContext(), cluster)
|
||||
if err != nil {
|
||||
klog.Warningf("%v", err)
|
||||
}
|
||||
|
||||
oldGroup, err := clientset.InstanceGroupsFor(cluster).Get(ctx, groupName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading InstanceGroup %q: %v", groupName, err)
|
||||
|
|
@ -290,7 +290,7 @@ func updateInstanceGroup(ctx context.Context, clientset simple.Clientset, channe
|
|||
|
||||
// We need the full cluster spec to perform deep validation
|
||||
// Note that we don't write it back though
|
||||
err = cloudup.PerformAssignments(cluster, cloud)
|
||||
err = cloudup.PerformAssignments(cluster, clientset.VFSContext(), cloud)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error populating configuration: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import (
|
|||
"k8s.io/kops/pkg/commands/commandutils"
|
||||
"k8s.io/kops/pkg/kopscodecs"
|
||||
"k8s.io/kops/util/pkg/tables"
|
||||
"k8s.io/kops/util/pkg/vfs"
|
||||
"k8s.io/kubectl/pkg/util/i18n"
|
||||
"k8s.io/kubectl/pkg/util/templates"
|
||||
)
|
||||
|
|
@ -157,7 +158,7 @@ func RunGetClusters(ctx context.Context, f commandutils.Factory, out io.Writer,
|
|||
|
||||
if options.FullSpec {
|
||||
var err error
|
||||
clusters, err = fullClusterSpecs(ctx, clusters)
|
||||
clusters, err = fullClusterSpecs(ctx, client.VFSContext(), clusters)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -278,10 +279,10 @@ func fullOutputYAML(out io.Writer, args ...runtime.Object) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func fullClusterSpecs(ctx context.Context, clusters []*kopsapi.Cluster) ([]*kopsapi.Cluster, error) {
|
||||
func fullClusterSpecs(ctx context.Context, vfsContext *vfs.VFSContext, clusters []*kopsapi.Cluster) ([]*kopsapi.Cluster, error) {
|
||||
var fullSpecs []*kopsapi.Cluster
|
||||
for _, cluster := range clusters {
|
||||
configBase, err := registry.ConfigBase(cluster)
|
||||
configBase, err := registry.ConfigBase(vfsContext, cluster)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading full cluster spec for %q: %v", cluster.ObjectMeta.Name, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ func RunReplace(ctx context.Context, f *util.Factory, out io.Writer, c *ReplaceO
|
|||
return fmt.Errorf("cluster %v does not exist (try adding --force flag)", clusterName)
|
||||
}
|
||||
|
||||
err = cloudup.PerformAssignments(v, cloud)
|
||||
err = cloudup.PerformAssignments(v, vfsContext, cloud)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error populating configuration: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -384,7 +384,7 @@ func retrieveClusterRefs(ctx context.Context, f commandutils.Factory, clusterNam
|
|||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
channel, err := cloudup.ChannelForCluster(cluster)
|
||||
channel, err := cloudup.ChannelForCluster(clientset.VFSContext(), cluster)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ func RunToolBoxTemplate(f commandutils.Factory, out io.Writer, options *ToolboxT
|
|||
}
|
||||
}
|
||||
|
||||
channel, err := kopsapi.LoadChannel(options.channel)
|
||||
channel, err := kopsapi.LoadChannel(f.VFSContext(), options.channel)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error loading channel %q: %v", options.channel, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ func RunUpgradeCluster(ctx context.Context, f *util.Factory, out io.Writer, opti
|
|||
})
|
||||
}
|
||||
|
||||
channel, err := kopsapi.LoadChannel(channelLocation)
|
||||
channel, err := kopsapi.LoadChannel(f.VFSContext(), channelLocation)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error loading channel %q: %v", channelLocation, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ func up(vfsContext *vfs.VFSContext, ctx context.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := cloudup.PerformAssignments(cluster, cloud); err != nil {
|
||||
if err := cloudup.PerformAssignments(cluster, vfsContext, cloud); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -249,7 +249,7 @@ func BuildNodeupModelContext(model *testutils.Model) (*NodeupModelContext, error
|
|||
return nil, fmt.Errorf("error from BuildCloud: %v", err)
|
||||
}
|
||||
|
||||
err = cloudup.PerformAssignments(model.Cluster, cloud)
|
||||
err = cloudup.PerformAssignments(model.Cluster, vfs.Context, cloud)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error from PerformAssignments: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ func ResolveChannel(location string) (*url.URL, error) {
|
|||
}
|
||||
|
||||
// LoadChannel loads a Channel object from the specified VFS location
|
||||
func LoadChannel(location string) (*Channel, error) {
|
||||
func LoadChannel(vfsContext *vfs.VFSContext, location string) (*Channel, error) {
|
||||
resolvedURL, err := ResolveChannel(location)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -141,7 +141,7 @@ func LoadChannel(location string) (*Channel, error) {
|
|||
resolved := resolvedURL.String()
|
||||
|
||||
klog.V(2).Infof("Loading channel from %q", resolved)
|
||||
channelBytes, err := vfs.Context.ReadFile(resolved)
|
||||
channelBytes, err := vfsContext.ReadFile(resolved)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading channel %q: %v", resolved, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,11 +33,11 @@ const (
|
|||
PathKopsVersionUpdated = "kops-version.txt"
|
||||
)
|
||||
|
||||
func ConfigBase(c *api.Cluster) (vfs.Path, error) {
|
||||
func ConfigBase(vfsContext *vfs.VFSContext, c *api.Cluster) (vfs.Path, error) {
|
||||
if c.Spec.ConfigBase == "" {
|
||||
return nil, field.Required(field.NewPath("spec", "configBase"), "")
|
||||
}
|
||||
configBase, err := vfs.Context.BuildVfsPath(c.Spec.ConfigBase)
|
||||
configBase, err := vfsContext.BuildVfsPath(c.Spec.ConfigBase)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing ConfigBase %q: %v", c.Spec.ConfigBase, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,10 +23,11 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
"k8s.io/kops/pkg/apis/kops"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
"k8s.io/kops/util/pkg/vfs"
|
||||
)
|
||||
|
||||
func ValidateClusterUpdate(obj *kops.Cluster, status *kops.ClusterStatus, old *kops.Cluster) field.ErrorList {
|
||||
allErrs := ValidateCluster(obj, false)
|
||||
func ValidateClusterUpdate(obj *kops.Cluster, status *kops.ClusterStatus, old *kops.Cluster, vfsContext *vfs.VFSContext) field.ErrorList {
|
||||
allErrs := ValidateCluster(obj, false, vfsContext)
|
||||
|
||||
// Validate etcd cluster changes
|
||||
{
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import (
|
|||
// legacy contains validation functions that don't match the apimachinery style
|
||||
|
||||
// ValidateCluster is responsible for checking the validity of the Cluster spec
|
||||
func ValidateCluster(c *kops.Cluster, strict bool) field.ErrorList {
|
||||
func ValidateCluster(c *kops.Cluster, strict bool, vfsContext *vfs.VFSContext) field.ErrorList {
|
||||
fieldSpec := field.NewPath("spec")
|
||||
allErrs := field.ErrorList{}
|
||||
|
||||
|
|
@ -200,12 +200,12 @@ func ValidateCluster(c *kops.Cluster, strict bool) field.ErrorList {
|
|||
allErrs = append(allErrs, newValidateCluster(c, strict)...)
|
||||
|
||||
said := c.Spec.ServiceAccountIssuerDiscovery
|
||||
allErrs = append(allErrs, validateServiceAccountIssuerDiscovery(c, said, fieldSpec.Child("serviceAccountIssuerDiscovery"))...)
|
||||
allErrs = append(allErrs, validateServiceAccountIssuerDiscovery(c, said, fieldSpec.Child("serviceAccountIssuerDiscovery"), vfsContext)...)
|
||||
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func validateServiceAccountIssuerDiscovery(c *kops.Cluster, said *kops.ServiceAccountIssuerDiscoveryConfig, fieldSpec *field.Path) field.ErrorList {
|
||||
func validateServiceAccountIssuerDiscovery(c *kops.Cluster, said *kops.ServiceAccountIssuerDiscoveryConfig, fieldSpec *field.Path, vfsContext *vfs.VFSContext) field.ErrorList {
|
||||
if said == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -213,7 +213,7 @@ func validateServiceAccountIssuerDiscovery(c *kops.Cluster, said *kops.ServiceAc
|
|||
saidStore := said.DiscoveryStore
|
||||
if saidStore != "" {
|
||||
saidStoreField := fieldSpec.Child("serviceAccountIssuerDiscovery", "discoveryStore")
|
||||
base, err := vfs.Context.BuildVfsPath(saidStore)
|
||||
base, err := vfsContext.BuildVfsPath(saidStore)
|
||||
if err != nil {
|
||||
allErrs = append(allErrs, field.Invalid(saidStoreField, saidStore, "not a valid VFS path"))
|
||||
} else {
|
||||
|
|
@ -256,8 +256,8 @@ func validateSubnetCIDR(networkCIDRs []*net.IPNet, subnetCIDR *net.IPNet) bool {
|
|||
}
|
||||
|
||||
// DeepValidate is responsible for validating the instancegroups within the cluster spec
|
||||
func DeepValidate(c *kops.Cluster, groups []*kops.InstanceGroup, strict bool, cloud fi.Cloud) error {
|
||||
if errs := ValidateCluster(c, strict); len(errs) != 0 {
|
||||
func DeepValidate(c *kops.Cluster, groups []*kops.InstanceGroup, strict bool, vfsContext *vfs.VFSContext, cloud fi.Cloud) error {
|
||||
if errs := ValidateCluster(c, strict, vfsContext); len(errs) != 0 {
|
||||
return errs.ToAggregate()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ func (c *RESTClientset) UpdateCluster(ctx context.Context, cluster *kops.Cluster
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := validation.ValidateClusterUpdate(cluster, status, old).ToAggregate(); err != nil {
|
||||
if err := validation.ValidateClusterUpdate(cluster, status, old, c.VFSContext()).ToAggregate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -126,7 +126,7 @@ func (c *RESTClientset) SSHCredentialStore(cluster *kops.Cluster) (fi.SSHCredent
|
|||
}
|
||||
|
||||
func (c *RESTClientset) DeleteCluster(ctx context.Context, cluster *kops.Cluster) error {
|
||||
configBase, err := registry.ConfigBase(cluster)
|
||||
configBase, err := registry.ConfigBase(c.VFSContext(), cluster)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ func (c *VFSClientset) VFSContext() *vfs.VFSContext {
|
|||
}
|
||||
|
||||
func (c *VFSClientset) clusters() *ClusterVFS {
|
||||
return newClusterVFS(c.basePath)
|
||||
return newClusterVFS(c.VFSContext(), c.basePath)
|
||||
}
|
||||
|
||||
// GetCluster implements the GetCluster method of simple.Clientset for a VFS-backed state store
|
||||
|
|
@ -87,7 +87,7 @@ func (c *VFSClientset) AddonsFor(cluster *kops.Cluster) simple.AddonsClient {
|
|||
|
||||
func (c *VFSClientset) SecretStore(cluster *kops.Cluster) (fi.SecretStore, error) {
|
||||
if cluster.Spec.SecretStore == "" {
|
||||
configBase, err := registry.ConfigBase(cluster)
|
||||
configBase, err := registry.ConfigBase(c.VFSContext(), cluster)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -120,7 +120,7 @@ func (c *VFSClientset) SSHCredentialStore(cluster *kops.Cluster) (fi.SSHCredenti
|
|||
|
||||
func (c *VFSClientset) pkiPath(cluster *kops.Cluster) (vfs.Path, error) {
|
||||
if cluster.Spec.KeyStore == "" {
|
||||
configBase, err := registry.ConfigBase(cluster)
|
||||
configBase, err := registry.ConfigBase(c.VFSContext(), cluster)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -232,7 +232,7 @@ func (c *VFSClientset) DeleteCluster(ctx context.Context, cluster *kops.Cluster)
|
|||
}
|
||||
}
|
||||
|
||||
configBase, err := registry.ConfigBase(cluster)
|
||||
configBase, err := registry.ConfigBase(c.VFSContext(), cluster)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,9 +41,9 @@ type ClusterVFS struct {
|
|||
commonVFS
|
||||
}
|
||||
|
||||
func newClusterVFS(basePath vfs.Path) *ClusterVFS {
|
||||
func newClusterVFS(vfsContext *vfs.VFSContext, basePath vfs.Path) *ClusterVFS {
|
||||
c := &ClusterVFS{}
|
||||
c.init("Cluster", basePath, StoreVersion)
|
||||
c.init("Cluster", vfsContext, basePath, StoreVersion)
|
||||
return c
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ func (c *ClusterVFS) List(options metav1.ListOptions) (*api.ClusterList, error)
|
|||
func (r *ClusterVFS) Create(c *api.Cluster) (*api.Cluster, error) {
|
||||
ctx := context.TODO()
|
||||
|
||||
if errs := validation.ValidateCluster(c, false); len(errs) != 0 {
|
||||
if errs := validation.ValidateCluster(c, false, r.vfsContext); len(errs) != 0 {
|
||||
return nil, errs.ToAggregate()
|
||||
}
|
||||
|
||||
|
|
@ -143,7 +143,7 @@ func (r *ClusterVFS) Update(c *api.Cluster, status *api.ClusterStatus) (*api.Clu
|
|||
return nil, errors.NewNotFound(schema.GroupResource{Group: api.GroupName, Resource: "Cluster"}, clusterName)
|
||||
}
|
||||
|
||||
if err := validation.ValidateClusterUpdate(c, status, old).ToAggregate(); err != nil {
|
||||
if err := validation.ValidateClusterUpdate(c, status, old, r.vfsContext).ToAggregate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,13 +41,14 @@ var StoreVersion = v1alpha2.SchemeGroupVersion
|
|||
type ValidationFunction func(o runtime.Object) error
|
||||
|
||||
type commonVFS struct {
|
||||
kind string
|
||||
basePath vfs.Path
|
||||
encoder runtime.Encoder
|
||||
validate ValidationFunction
|
||||
kind string
|
||||
vfsContext *vfs.VFSContext
|
||||
basePath vfs.Path
|
||||
encoder runtime.Encoder
|
||||
validate ValidationFunction
|
||||
}
|
||||
|
||||
func (c *commonVFS) init(kind string, basePath vfs.Path, storeVersion runtime.GroupVersioner) {
|
||||
func (c *commonVFS) init(kind string, vfsContext *vfs.VFSContext, basePath vfs.Path, storeVersion runtime.GroupVersioner) {
|
||||
codecs := kopscodecs.Codecs
|
||||
yaml, ok := runtime.SerializerInfoForMediaType(codecs.SupportedMediaTypes(), "application/yaml")
|
||||
if !ok {
|
||||
|
|
@ -56,6 +57,7 @@ func (c *commonVFS) init(kind string, basePath vfs.Path, storeVersion runtime.Gr
|
|||
c.encoder = codecs.EncoderForVersion(yaml.Serializer, storeVersion)
|
||||
|
||||
c.kind = kind
|
||||
c.vfsContext = vfsContext
|
||||
c.basePath = basePath
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ func newInstanceGroupVFS(c *VFSClientset, cluster *kopsapi.Cluster) *InstanceGro
|
|||
cluster: cluster,
|
||||
clusterName: clusterName,
|
||||
}
|
||||
r.init(kind, c.basePath.Join(clusterName, "instancegroup"), StoreVersion)
|
||||
r.init(kind, c.VFSContext(), c.basePath.Join(clusterName, "instancegroup"), StoreVersion)
|
||||
r.validate = func(o runtime.Object) error {
|
||||
return validation.ValidateInstanceGroup(o.(*kopsapi.InstanceGroup), nil, false).ToAggregate()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,12 @@ limitations under the License.
|
|||
|
||||
package commandutils
|
||||
|
||||
import "k8s.io/kops/pkg/client/simple"
|
||||
import (
|
||||
"k8s.io/kops/pkg/client/simple"
|
||||
"k8s.io/kops/util/pkg/vfs"
|
||||
)
|
||||
|
||||
type Factory interface {
|
||||
KopsClient() (simple.Clientset, error)
|
||||
VFSContext() *vfs.VFSContext
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ func UpdateCluster(ctx context.Context, clientset simple.Clientset, cluster *kop
|
|||
return err
|
||||
}
|
||||
|
||||
err = cloudup.PerformAssignments(cluster, cloud)
|
||||
err = cloudup.PerformAssignments(cluster, clientset.VFSContext(), cloud)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error populating configuration: %v", err)
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ func UpdateCluster(ctx context.Context, clientset simple.Clientset, cluster *kop
|
|||
return err
|
||||
}
|
||||
|
||||
err = validation.DeepValidate(fullCluster, instanceGroups, true, nil)
|
||||
err = validation.DeepValidate(fullCluster, instanceGroups, true, clientset.VFSContext(), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ func UpdateInstanceGroup(ctx context.Context, clientset simple.Clientset, cluste
|
|||
return err
|
||||
}
|
||||
|
||||
err = cloudup.PerformAssignments(cluster, cloud)
|
||||
err = cloudup.PerformAssignments(cluster, clientset.VFSContext(), cloud)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error populating configuration: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ func getTestSetupOS(t *testing.T, ctx context.Context) (*RollingUpdateCluster, *
|
|||
inCluster.Spec.Networking.Topology.ControlPlane = kopsapi.TopologyPrivate
|
||||
inCluster.Spec.Networking.Topology.Nodes = kopsapi.TopologyPrivate
|
||||
|
||||
err := cloudup.PerformAssignments(inCluster, mockcloud)
|
||||
err := cloudup.PerformAssignments(inCluster, vfs.Context, mockcloud)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to perform assignments: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
|
|||
}
|
||||
}
|
||||
|
||||
channel, err := ChannelForCluster(c.Cluster)
|
||||
channel, err := ChannelForCluster(c.Clientset.VFSContext(), c.Cluster)
|
||||
if err != nil {
|
||||
klog.Warningf("%v", err)
|
||||
}
|
||||
|
|
@ -297,7 +297,7 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
|
|||
|
||||
cloud := c.Cloud
|
||||
|
||||
err = validation.DeepValidate(c.Cluster, c.InstanceGroups, true, cloud)
|
||||
err = validation.DeepValidate(c.Cluster, c.InstanceGroups, true, c.Clientset.VFSContext(), cloud)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -1136,12 +1136,12 @@ func buildPermalink(key, anchor string) string {
|
|||
return url
|
||||
}
|
||||
|
||||
func ChannelForCluster(c *kops.Cluster) (*kops.Channel, error) {
|
||||
func ChannelForCluster(vfsContext *vfs.VFSContext, c *kops.Cluster) (*kops.Channel, error) {
|
||||
channelLocation := c.Spec.Channel
|
||||
if channelLocation == "" {
|
||||
channelLocation = kops.DefaultChannel
|
||||
}
|
||||
return kops.LoadChannel(channelLocation)
|
||||
return kops.LoadChannel(vfsContext, channelLocation)
|
||||
}
|
||||
|
||||
// needsMounterAsset checks if we need the mounter program
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ func runChannelBuilderTest(t *testing.T, key string, addonManifests []string) {
|
|||
t.Fatalf("error from BuildCloud: %v", err)
|
||||
}
|
||||
|
||||
if err := PerformAssignments(cluster, cloud); err != nil {
|
||||
if err := PerformAssignments(cluster, vfs.Context, cloud); err != nil {
|
||||
t.Fatalf("error from PerformAssignments for %q: %v", key, err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import (
|
|||
kopsapi "k8s.io/kops/pkg/apis/kops"
|
||||
"k8s.io/kops/pkg/apis/kops/validation"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
"k8s.io/kops/util/pkg/vfs"
|
||||
)
|
||||
|
||||
func TestDeepValidate_OK(t *testing.T) {
|
||||
|
|
@ -33,7 +34,7 @@ func TestDeepValidate_OK(t *testing.T) {
|
|||
groups = append(groups, buildMinimalMasterInstanceGroup(subnet.Name))
|
||||
groups = append(groups, buildMinimalNodeInstanceGroup(subnet.Name))
|
||||
}
|
||||
err := validation.DeepValidate(c, groups, true, nil)
|
||||
err := validation.DeepValidate(c, groups, true, vfs.Context, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Expected no error from DeepValidate, got %v", err)
|
||||
}
|
||||
|
|
@ -174,7 +175,7 @@ func TestDeepValidate_MissingEtcdMember(t *testing.T) {
|
|||
}
|
||||
|
||||
func expectErrorFromDeepValidate(t *testing.T, c *kopsapi.Cluster, groups []*kopsapi.InstanceGroup, message string) {
|
||||
err := validation.DeepValidate(c, groups, true, nil)
|
||||
err := validation.DeepValidate(c, groups, true, vfs.Context, nil)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error %q from DeepValidate (strict=true), not no error raised", message)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ import (
|
|||
// PerformAssignments is called on create, as well as an update. In fact
|
||||
// any time Run() is called in apply_cluster.go we will reach this function.
|
||||
// Please do all after-market logic here.
|
||||
func PerformAssignments(c *kops.Cluster, cloud fi.Cloud) error {
|
||||
func PerformAssignments(c *kops.Cluster, vfsContext *vfs.VFSContext, cloud fi.Cloud) error {
|
||||
ctx := context.TODO()
|
||||
|
||||
for i := range c.Spec.EtcdClusters {
|
||||
|
|
@ -133,15 +133,15 @@ func PerformAssignments(c *kops.Cluster, cloud fi.Cloud) error {
|
|||
}
|
||||
c.Spec.Networking.EgressProxy = proxy
|
||||
|
||||
return ensureKubernetesVersion(c)
|
||||
return ensureKubernetesVersion(vfsContext, c)
|
||||
}
|
||||
|
||||
// ensureKubernetesVersion populates KubernetesVersion, if it is not already set
|
||||
// It will be populated with the latest stable kubernetes version, or the version from the channel
|
||||
func ensureKubernetesVersion(c *kops.Cluster) error {
|
||||
func ensureKubernetesVersion(vfsContext *vfs.VFSContext, c *kops.Cluster) error {
|
||||
if c.Spec.KubernetesVersion == "" {
|
||||
if c.Spec.Channel != "" {
|
||||
channel, err := kops.LoadChannel(c.Spec.Channel)
|
||||
channel, err := kops.LoadChannel(vfsContext, c.Spec.Channel)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ func NewCluster(opt *NewClusterOptions, clientset simple.Clientset) (*NewCluster
|
|||
if opt.Channel == "" {
|
||||
opt.Channel = api.DefaultChannel
|
||||
}
|
||||
channel, err := api.LoadChannel(opt.Channel)
|
||||
channel, err := api.LoadChannel(clientset.VFSContext(), opt.Channel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kops/util/pkg/vfs"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
|
@ -464,7 +465,7 @@ func TestDefaultImage(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
channel, err := api.LoadChannel("file://tests/channels/channel.yaml")
|
||||
channel, err := api.LoadChannel(vfs.NewTestingVFSContext(), "file://tests/channels/channel.yaml")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to load test channel: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ func PopulateClusterSpec(ctx context.Context, clientset simple.Clientset, cluste
|
|||
// struct is falling through..
|
||||
// @kris-nova
|
||||
func (c *populateClusterSpec) run(ctx context.Context, clientset simple.Clientset) error {
|
||||
if errs := validation.ValidateCluster(c.InputCluster, false); len(errs) != 0 {
|
||||
if errs := validation.ValidateCluster(c.InputCluster, false, clientset.VFSContext()); len(errs) != 0 {
|
||||
return errs.ToAggregate()
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ func (c *populateClusterSpec) run(ctx context.Context, clientset simple.Clientse
|
|||
return err
|
||||
}
|
||||
|
||||
err = PerformAssignments(cluster, cloud)
|
||||
err = PerformAssignments(cluster, clientset.VFSContext(), cloud)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -314,7 +314,7 @@ func (c *populateClusterSpec) run(ctx context.Context, clientset simple.Clientse
|
|||
*fullCluster = *cluster
|
||||
fullCluster.Spec = *completed
|
||||
|
||||
if errs := validation.ValidateCluster(fullCluster, true); len(errs) != 0 {
|
||||
if errs := validation.ValidateCluster(fullCluster, true, clientset.VFSContext()); len(errs) != 0 {
|
||||
return fmt.Errorf("completed cluster failed validation: %v", errs.ToAggregate())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ func TestPopulateCluster_Default_NoError(t *testing.T) {
|
|||
ctx := context.TODO()
|
||||
cloud, c := buildMinimalCluster()
|
||||
|
||||
err := PerformAssignments(c, cloud)
|
||||
err := PerformAssignments(c, vfs.Context, cloud)
|
||||
if err != nil {
|
||||
t.Fatalf("error from PerformAssignments: %v", err)
|
||||
}
|
||||
|
|
@ -95,7 +95,7 @@ func TestPopulateCluster_Subnets(t *testing.T) {
|
|||
Enabled: fi.PtrTo(true),
|
||||
}
|
||||
|
||||
err := PerformAssignments(c, cloud)
|
||||
err := PerformAssignments(c, vfs.Context, cloud)
|
||||
require.NoError(t, err, "PerformAssignments")
|
||||
|
||||
full, err := mockedPopulateClusterSpec(ctx, c, cloud)
|
||||
|
|
@ -131,7 +131,7 @@ func TestPopulateCluster_Docker_Spec(t *testing.T) {
|
|||
LogOpt: []string{"env=FOO"},
|
||||
}
|
||||
|
||||
err := PerformAssignments(c, cloud)
|
||||
err := PerformAssignments(c, vfs.Context, cloud)
|
||||
if err != nil {
|
||||
t.Fatalf("error from PerformAssignments: %v", err)
|
||||
}
|
||||
|
|
@ -166,7 +166,7 @@ func TestPopulateCluster_StorageDefault(t *testing.T) {
|
|||
ctx := context.TODO()
|
||||
cloud, c := buildMinimalCluster()
|
||||
|
||||
err := PerformAssignments(c, cloud)
|
||||
err := PerformAssignments(c, vfs.Context, cloud)
|
||||
if err != nil {
|
||||
t.Fatalf("error from PerformAssignments: %v", err)
|
||||
}
|
||||
|
|
@ -185,7 +185,7 @@ func TestPopulateCluster_EvictionHard(t *testing.T) {
|
|||
ctx := context.TODO()
|
||||
cloud, c := buildMinimalCluster()
|
||||
|
||||
err := PerformAssignments(c, cloud)
|
||||
err := PerformAssignments(c, vfs.Context, cloud)
|
||||
if err != nil {
|
||||
t.Fatalf("error from PerformAssignments: %v", err)
|
||||
}
|
||||
|
|
@ -211,7 +211,7 @@ func build(c *kopsapi.Cluster) (*kopsapi.Cluster, error) {
|
|||
return nil, fmt.Errorf("error from BuildCloud: %v", err)
|
||||
}
|
||||
|
||||
err = PerformAssignments(c, cloud)
|
||||
err = PerformAssignments(c, vfs.Context, cloud)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error from PerformAssignments: %v", err)
|
||||
}
|
||||
|
|
@ -234,7 +234,7 @@ func TestPopulateCluster_Custom_CIDR(t *testing.T) {
|
|||
{Name: "subnet-us-test-1c", Zone: "us-test-1c", CIDR: "172.20.2.64/27", Type: kopsapi.SubnetTypePublic},
|
||||
}
|
||||
|
||||
err := PerformAssignments(c, cloud)
|
||||
err := PerformAssignments(c, vfs.Context, cloud)
|
||||
if err != nil {
|
||||
t.Fatalf("error from PerformAssignments: %v", err)
|
||||
}
|
||||
|
|
@ -253,7 +253,7 @@ func TestPopulateCluster_IsolateMasters(t *testing.T) {
|
|||
cloud, c := buildMinimalCluster()
|
||||
c.Spec.Networking.IsolateControlPlane = fi.PtrTo(true)
|
||||
|
||||
err := PerformAssignments(c, cloud)
|
||||
err := PerformAssignments(c, vfs.Context, cloud)
|
||||
if err != nil {
|
||||
t.Fatalf("error from PerformAssignments: %v", err)
|
||||
}
|
||||
|
|
@ -275,7 +275,7 @@ func TestPopulateCluster_IsolateMastersFalse(t *testing.T) {
|
|||
cloud, c := buildMinimalCluster()
|
||||
// default: c.Spec.IsolateControlPlane = fi.PtrTo(false)
|
||||
|
||||
err := PerformAssignments(c, cloud)
|
||||
err := PerformAssignments(c, vfs.Context, cloud)
|
||||
if err != nil {
|
||||
t.Fatalf("error from PerformAssignments: %v", err)
|
||||
}
|
||||
|
|
@ -386,7 +386,7 @@ func TestPopulateCluster_AnonymousAuth(t *testing.T) {
|
|||
cloud, c := buildMinimalCluster()
|
||||
c.Spec.KubernetesVersion = "1.20.0"
|
||||
|
||||
err := PerformAssignments(c, cloud)
|
||||
err := PerformAssignments(c, vfs.Context, cloud)
|
||||
if err != nil {
|
||||
t.Fatalf("error from PerformAssignments: %v", err)
|
||||
}
|
||||
|
|
@ -437,7 +437,7 @@ func TestPopulateCluster_KubeController_High_Enough_Version(t *testing.T) {
|
|||
cloud, c := buildMinimalCluster()
|
||||
c.Spec.KubernetesVersion = "v1.9.0"
|
||||
|
||||
err := PerformAssignments(c, cloud)
|
||||
err := PerformAssignments(c, vfs.Context, cloud)
|
||||
if err != nil {
|
||||
t.Fatalf("error from PerformAssignments: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import (
|
|||
api "k8s.io/kops/pkg/apis/kops"
|
||||
"k8s.io/kops/pkg/apis/kops/validation"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
"k8s.io/kops/util/pkg/vfs"
|
||||
)
|
||||
|
||||
const testAWSRegion = "us-test-1"
|
||||
|
|
@ -34,7 +35,7 @@ func buildDefaultCluster(t *testing.T) *api.Cluster {
|
|||
ctx := context.TODO()
|
||||
cloud, c := buildMinimalCluster()
|
||||
|
||||
err := PerformAssignments(c, cloud)
|
||||
err := PerformAssignments(c, vfs.Context, cloud)
|
||||
if err != nil {
|
||||
t.Fatalf("error from PerformAssignments: %v", err)
|
||||
}
|
||||
|
|
@ -85,11 +86,11 @@ func buildDefaultCluster(t *testing.T) *api.Cluster {
|
|||
|
||||
func TestValidateFull_Default_Validates(t *testing.T) {
|
||||
c := buildDefaultCluster(t)
|
||||
if errs := validation.ValidateCluster(c, false); len(errs) != 0 {
|
||||
if errs := validation.ValidateCluster(c, false, vfs.Context); len(errs) != 0 {
|
||||
klog.Infof("Cluster: %v", c)
|
||||
t.Fatalf("Validate gave unexpected error (strict=false): %v", errs.ToAggregate())
|
||||
}
|
||||
if errs := validation.ValidateCluster(c, true); len(errs) != 0 {
|
||||
if errs := validation.ValidateCluster(c, true, vfs.Context); len(errs) != 0 {
|
||||
t.Fatalf("Validate gave unexpected error (strict=true): %v", errs.ToAggregate())
|
||||
}
|
||||
}
|
||||
|
|
@ -199,7 +200,7 @@ func TestValidate_ContainerRegistry_and_ContainerProxy_exclusivity(t *testing.T)
|
|||
}
|
||||
|
||||
func expectErrorFromValidate(t *testing.T, c *api.Cluster, message string) {
|
||||
errs := validation.ValidateCluster(c, false)
|
||||
errs := validation.ValidateCluster(c, false, vfs.Context)
|
||||
if len(errs) == 0 {
|
||||
t.Fatalf("Expected error from Validate")
|
||||
}
|
||||
|
|
@ -210,7 +211,7 @@ func expectErrorFromValidate(t *testing.T, c *api.Cluster, message string) {
|
|||
}
|
||||
|
||||
func expectNoErrorFromValidate(t *testing.T, c *api.Cluster) {
|
||||
errs := validation.ValidateCluster(c, false)
|
||||
errs := validation.ValidateCluster(c, false, vfs.Context)
|
||||
if len(errs) != 0 {
|
||||
t.Fatalf("Unexpected error from Validate: %v", errs.ToAggregate())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue