move m.machinesets back out of Manager for now - trying to initialise too early

This commit is contained in:
Jim Minter 2019-11-28 18:21:26 -06:00
Родитель 221a61c4fa
Коммит 1b4b6228ea
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 0730CBDA10D1A2D3
2 изменённых файлов: 17 добавлений и 19 удалений

Просмотреть файл

@ -7,12 +7,10 @@ import (
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/resources" "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/resources"
"github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure" "github.com/Azure/go-autorest/autorest/azure"
machine "github.com/openshift/cluster-api/pkg/client/clientset_generated/clientset/typed/machine/v1beta1"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/jim-minter/rp/pkg/api" "github.com/jim-minter/rp/pkg/api"
"github.com/jim-minter/rp/pkg/database" "github.com/jim-minter/rp/pkg/database"
"github.com/jim-minter/rp/pkg/util/restconfig"
) )
type Manager struct { type Manager struct {
@ -23,8 +21,6 @@ type Manager struct {
recordsets dns.RecordSetsClient recordsets dns.RecordSetsClient
groups resources.GroupsClient groups resources.GroupsClient
machinesets machine.MachineSetInterface
oc *api.OpenShiftCluster oc *api.OpenShiftCluster
domain string domain string
} }
@ -51,16 +47,5 @@ func NewManager(log *logrus.Entry, db database.OpenShiftClusters, authorizer aut
m.groups.Authorizer = authorizer m.groups.Authorizer = authorizer
m.groups.Client.PollingDuration = time.Hour m.groups.Client.PollingDuration = time.Hour
restConfig, err := restconfig.RestConfig(oc.Properties.AdminKubeconfig)
if err != nil {
return nil, err
}
cli, err := machine.NewForConfig(restConfig)
if err != nil {
return nil, err
}
m.machinesets = cli.MachineSets("openshift-machine-api")
return m, nil return m, nil
} }

Просмотреть файл

@ -7,9 +7,12 @@ import (
"github.com/Azure/go-autorest/autorest/to" "github.com/Azure/go-autorest/autorest/to"
machinev1beta1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" machinev1beta1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
machine "github.com/openshift/cluster-api/pkg/client/clientset_generated/clientset/typed/machine/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/util/retry" "k8s.io/client-go/util/retry"
"github.com/jim-minter/rp/pkg/util/restconfig"
) )
func find(xs interface{}, f func(int, int) bool) interface{} { func find(xs interface{}, f func(int, int) bool) interface{} {
@ -24,7 +27,17 @@ func find(xs interface{}, f func(int, int) bool) interface{} {
} }
func (b *Manager) Update(ctx context.Context) error { func (b *Manager) Update(ctx context.Context) error {
machinesets, err := b.machinesets.List(metav1.ListOptions{}) restConfig, err := restconfig.RestConfig(b.oc.Properties.AdminKubeconfig)
if err != nil {
return err
}
cli, err := machine.NewForConfig(restConfig)
if err != nil {
return err
}
machinesets, err := cli.MachineSets("openshift-machine-api").List(metav1.ListOptions{})
if err != nil { if err != nil {
return err return err
} }
@ -53,14 +66,14 @@ func (b *Manager) Update(ctx context.Context) error {
want := *machineset.Spec.Replicas want := *machineset.Spec.Replicas
err := retry.RetryOnConflict(retry.DefaultRetry, func() error { err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
machineset, err := b.machinesets.Get(machineset.Name, metav1.GetOptions{}) machineset, err := cli.MachineSets(machineset.Namespace).Get(machineset.Name, metav1.GetOptions{})
if err != nil { if err != nil {
return err return err
} }
b.log.Printf("scaling machineset %s to %d replicas", machineset.Name, want) b.log.Printf("scaling machineset %s to %d replicas", machineset.Name, want)
machineset.Spec.Replicas = to.Int32Ptr(want) machineset.Spec.Replicas = to.Int32Ptr(want)
_, err = b.machinesets.Update(machineset) _, err = cli.MachineSets(machineset.Namespace).Update(machineset)
return err return err
}) })
if err != nil { if err != nil {
@ -73,7 +86,7 @@ func (b *Manager) Update(ctx context.Context) error {
b.log.Printf("waiting for machineset %s", machineset.Name) b.log.Printf("waiting for machineset %s", machineset.Name)
err := wait.PollImmediate(10*time.Second, 30*time.Minute, func() (bool, error) { err := wait.PollImmediate(10*time.Second, 30*time.Minute, func() (bool, error) {
m, err := b.machinesets.Get(machineset.Name, metav1.GetOptions{}) m, err := cli.MachineSets(machineset.Namespace).Get(machineset.Name, metav1.GetOptions{})
if err != nil { if err != nil {
return false, err return false, err
} }