mirror of https://github.com/kubernetes/kops.git
added dependencies between LB, LBbackend and LBfrontend tasks
This commit is contained in:
parent
43f8f8b29b
commit
e2a6207ea1
|
@ -78,13 +78,13 @@ func (b *APILoadBalancerModelBuilder) Build(c *fi.CloudupModelBuilderContext) er
|
||||||
lbBackend := &scalewaytasks.LBBackend{
|
lbBackend := &scalewaytasks.LBBackend{
|
||||||
Name: fi.PtrTo("lb-backend"),
|
Name: fi.PtrTo("lb-backend"),
|
||||||
Lifecycle: b.Lifecycle,
|
Lifecycle: b.Lifecycle,
|
||||||
LBName: fi.PtrTo(loadBalancerName),
|
|
||||||
Zone: fi.PtrTo(string(zone)),
|
Zone: fi.PtrTo(string(zone)),
|
||||||
ForwardProtocol: fi.PtrTo(string(lb.ProtocolTCP)),
|
ForwardProtocol: fi.PtrTo(string(lb.ProtocolTCP)),
|
||||||
ForwardPort: fi.PtrTo(int32(443)),
|
ForwardPort: fi.PtrTo(int32(443)),
|
||||||
ForwardPortAlgorithm: fi.PtrTo(string(lb.ForwardPortAlgorithmRoundrobin)),
|
ForwardPortAlgorithm: fi.PtrTo(string(lb.ForwardPortAlgorithmRoundrobin)),
|
||||||
StickySessions: fi.PtrTo(string(lb.StickySessionsTypeNone)),
|
StickySessions: fi.PtrTo(string(lb.StickySessionsTypeNone)),
|
||||||
ProxyProtocol: fi.PtrTo(string(lb.ProxyProtocolProxyProtocolUnknown)),
|
ProxyProtocol: fi.PtrTo(string(lb.ProxyProtocolProxyProtocolUnknown)),
|
||||||
|
LoadBalancer: loadBalancer,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.AddTask(lbBackend)
|
c.AddTask(lbBackend)
|
||||||
|
@ -92,9 +92,10 @@ func (b *APILoadBalancerModelBuilder) Build(c *fi.CloudupModelBuilderContext) er
|
||||||
lbFrontend := &scalewaytasks.LBFrontend{
|
lbFrontend := &scalewaytasks.LBFrontend{
|
||||||
Name: fi.PtrTo("lb-frontend"),
|
Name: fi.PtrTo("lb-frontend"),
|
||||||
Lifecycle: b.Lifecycle,
|
Lifecycle: b.Lifecycle,
|
||||||
LBName: fi.PtrTo(loadBalancerName),
|
|
||||||
Zone: fi.PtrTo(string(zone)),
|
Zone: fi.PtrTo(string(zone)),
|
||||||
InboundPort: fi.PtrTo(int32(443)),
|
InboundPort: fi.PtrTo(int32(443)),
|
||||||
|
LoadBalancer: loadBalancer,
|
||||||
|
LBBackend: lbBackend,
|
||||||
}
|
}
|
||||||
|
|
||||||
c.AddTask(lbFrontend)
|
c.AddTask(lbFrontend)
|
||||||
|
|
|
@ -38,7 +38,9 @@ type Instance struct {
|
||||||
Image *string
|
Image *string
|
||||||
Tags []string
|
Tags []string
|
||||||
Count int
|
Count int
|
||||||
|
|
||||||
UserData *fi.Resource
|
UserData *fi.Resource
|
||||||
|
LoadBalancer *LoadBalancer
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ fi.CloudupTask = &Instance{}
|
var _ fi.CloudupTask = &Instance{}
|
||||||
|
@ -188,6 +190,9 @@ func (_ *Instance) RenderScw(c *fi.CloudupContext, actual, expected, changes *In
|
||||||
return fmt.Errorf("error waiting for instance %s of group %q: %w", srv.Server.ID, fi.ValueOf(expected.Name), err)
|
return fmt.Errorf("error waiting for instance %s of group %q: %w", srv.Server.ID, fi.ValueOf(expected.Name), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If instance has control-plane role, we add its private IP to the list to add it to the lb's backend
|
||||||
|
if fi.ValueOf(expected.Role) == scaleway.TagRoleControlPlane {
|
||||||
|
|
||||||
// We update the server's infos (to get its IP)
|
// We update the server's infos (to get its IP)
|
||||||
server, err := instanceService.GetServer(&instance.GetServerRequest{
|
server, err := instanceService.GetServer(&instance.GetServerRequest{
|
||||||
Zone: zone,
|
Zone: zone,
|
||||||
|
@ -196,16 +201,33 @@ func (_ *Instance) RenderScw(c *fi.CloudupContext, actual, expected, changes *In
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("getting server %s: %s", srv.Server.ID, err)
|
return fmt.Errorf("getting server %s: %s", srv.Server.ID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If instance has control-plane role, we add its private IP to the list to add it to the lb's backend
|
|
||||||
for _, tag := range expected.Tags {
|
|
||||||
if tag == scaleway.TagNameRolePrefix+"="+scaleway.TagRoleControlPlane {
|
|
||||||
controlPlanePrivateIPs = append(controlPlanePrivateIPs, *server.Server.PrivateIP)
|
controlPlanePrivateIPs = append(controlPlanePrivateIPs, *server.Server.PrivateIP)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If newInstanceCount < 0, we need to delete instances of this group
|
||||||
|
if newInstanceCount < 0 {
|
||||||
|
|
||||||
|
igInstances, err := cloud.GetClusterServers(cloud.ClusterName(actual.Tags), actual.Name)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error deleting instance: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If IG is control-plane, we add the new servers' IPs to the load-balancer's back-end
|
for i := 0; i > newInstanceCount; i-- {
|
||||||
|
toDelete := igInstances[i*-1]
|
||||||
|
|
||||||
|
if fi.ValueOf(actual.Role) == scaleway.TagRoleControlPlane {
|
||||||
|
controlPlanePrivateIPs = append(controlPlanePrivateIPs, *toDelete.PrivateIP)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = cloud.DeleteServer(toDelete)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error deleting instance of group %s: %w", toDelete.Name, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If IG is control-plane, we need to update the load-balancer's back-end
|
||||||
if len(controlPlanePrivateIPs) > 0 {
|
if len(controlPlanePrivateIPs) > 0 {
|
||||||
lbService := cloud.LBService()
|
lbService := cloud.LBService()
|
||||||
zone := scw.Zone(cloud.Zone())
|
zone := scw.Zone(cloud.Zone())
|
||||||
|
@ -230,6 +252,8 @@ func (_ *Instance) RenderScw(c *fi.CloudupContext, actual, expected, changes *In
|
||||||
}
|
}
|
||||||
backEnd := backEnds.Backends[0]
|
backEnd := backEnds.Backends[0]
|
||||||
|
|
||||||
|
// If we are adding instances, we also need to add them to the load-balancer's backend
|
||||||
|
if newInstanceCount > 0 {
|
||||||
_, err = lbService.AddBackendServers(&lb.ZonedAPIAddBackendServersRequest{
|
_, err = lbService.AddBackendServers(&lb.ZonedAPIAddBackendServersRequest{
|
||||||
Zone: zone,
|
Zone: zone,
|
||||||
BackendID: backEnd.ID,
|
BackendID: backEnd.ID,
|
||||||
|
@ -239,6 +263,18 @@ func (_ *Instance) RenderScw(c *fi.CloudupContext, actual, expected, changes *In
|
||||||
return fmt.Errorf("adding servers' IPs to load-balancer's back-end: %w", err)
|
return fmt.Errorf("adding servers' IPs to load-balancer's back-end: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// If we are deleting instances, we also need to delete them from the load-balancer's backend
|
||||||
|
_, err = lbService.RemoveBackendServers(&lb.ZonedAPIRemoveBackendServersRequest{
|
||||||
|
Zone: zone,
|
||||||
|
BackendID: backEnd.ID,
|
||||||
|
ServerIP: controlPlanePrivateIPs,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("removing servers' IPs from load-balancer's back-end: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_, err = lbService.WaitForLb(&lb.ZonedAPIWaitForLBRequest{
|
_, err = lbService.WaitForLb(&lb.ZonedAPIWaitForLBRequest{
|
||||||
LBID: loadBalancer.ID,
|
LBID: loadBalancer.ID,
|
||||||
Zone: zone,
|
Zone: zone,
|
||||||
|
@ -249,22 +285,5 @@ func (_ *Instance) RenderScw(c *fi.CloudupContext, actual, expected, changes *In
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If newInstanceCount < 0, we need to delete instances of this group
|
|
||||||
if newInstanceCount < 0 {
|
|
||||||
|
|
||||||
igInstances, err := cloud.GetClusterServers(cloud.ClusterName(actual.Tags), actual.Name)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error deleting instance: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i > newInstanceCount; i-- {
|
|
||||||
toDelete := igInstances[i*-1]
|
|
||||||
err = cloud.DeleteServer(toDelete)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error deleting instance of group %s: %w", toDelete.Name, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,55 +25,40 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/scaleway"
|
"k8s.io/kops/upup/pkg/fi/cloudup/scaleway"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// +kops:fitask
|
||||||
type LBBackend struct {
|
type LBBackend struct {
|
||||||
Name *string
|
Name *string
|
||||||
Lifecycle fi.Lifecycle
|
Lifecycle fi.Lifecycle
|
||||||
|
|
||||||
ID *string
|
ID *string
|
||||||
LBName *string
|
|
||||||
Zone *string
|
Zone *string
|
||||||
ForwardProtocol *string
|
ForwardProtocol *string
|
||||||
ForwardPort *int32
|
ForwardPort *int32
|
||||||
ForwardPortAlgorithm *string
|
ForwardPortAlgorithm *string
|
||||||
StickySessions *string
|
StickySessions *string
|
||||||
ProxyProtocol *string
|
ProxyProtocol *string
|
||||||
|
|
||||||
|
LoadBalancer *LoadBalancer
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ fi.CloudupTask = &LBBackend{}
|
var _ fi.CloudupTask = &LBBackend{}
|
||||||
var _ fi.CompareWithID = &LBBackend{}
|
var _ fi.CompareWithID = &LBBackend{}
|
||||||
var _ fi.HasName = &LBBackend{}
|
|
||||||
|
|
||||||
func (l *LBBackend) CompareWithID() *string {
|
func (l *LBBackend) CompareWithID() *string {
|
||||||
return l.ID
|
return l.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LBBackend) GetName() *string {
|
|
||||||
return l.Name
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *LBBackend) Find(context *fi.CloudupContext) (*LBBackend, error) {
|
func (l *LBBackend) Find(context *fi.CloudupContext) (*LBBackend, error) {
|
||||||
cloud := context.T.Cloud.(scaleway.ScwCloud)
|
cloud := context.T.Cloud.(scaleway.ScwCloud)
|
||||||
lbService := cloud.LBService()
|
lbService := cloud.LBService()
|
||||||
|
|
||||||
lbResponse, err := lbService.ListLBs(&lb.ZonedAPIListLBsRequest{
|
|
||||||
Zone: scw.Zone(fi.ValueOf(l.Zone)),
|
|
||||||
Name: l.LBName,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("listing load-balancers: %w", err)
|
|
||||||
}
|
|
||||||
if lbResponse.TotalCount != 1 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
loadBalancer := lbResponse.LBs[0]
|
|
||||||
|
|
||||||
backendResponse, err := lbService.ListBackends(&lb.ZonedAPIListBackendsRequest{
|
backendResponse, err := lbService.ListBackends(&lb.ZonedAPIListBackendsRequest{
|
||||||
Zone: scw.Zone(cloud.Zone()),
|
Zone: scw.Zone(cloud.Zone()),
|
||||||
LBID: loadBalancer.ID,
|
LBID: fi.ValueOf(l.LoadBalancer.LBID),
|
||||||
Name: l.Name,
|
Name: l.Name,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("listing back-ends for load-balancer %s: %w", loadBalancer.ID, err)
|
return nil, fmt.Errorf("listing back-ends for load-balancer %s: %w", fi.ValueOf(l.LoadBalancer.LBID), err)
|
||||||
}
|
}
|
||||||
if backendResponse.TotalCount != 1 {
|
if backendResponse.TotalCount != 1 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -84,13 +69,15 @@ func (l *LBBackend) Find(context *fi.CloudupContext) (*LBBackend, error) {
|
||||||
Name: fi.PtrTo(backend.Name),
|
Name: fi.PtrTo(backend.Name),
|
||||||
Lifecycle: l.Lifecycle,
|
Lifecycle: l.Lifecycle,
|
||||||
ID: fi.PtrTo(backend.ID),
|
ID: fi.PtrTo(backend.ID),
|
||||||
LBName: fi.PtrTo(backend.LB.Name),
|
|
||||||
Zone: fi.PtrTo(string(backend.LB.Zone)),
|
Zone: fi.PtrTo(string(backend.LB.Zone)),
|
||||||
ForwardProtocol: fi.PtrTo(string(backend.ForwardProtocol)),
|
ForwardProtocol: fi.PtrTo(string(backend.ForwardProtocol)),
|
||||||
ForwardPort: fi.PtrTo(backend.ForwardPort),
|
ForwardPort: fi.PtrTo(backend.ForwardPort),
|
||||||
ForwardPortAlgorithm: fi.PtrTo(string(backend.ForwardPortAlgorithm)),
|
ForwardPortAlgorithm: fi.PtrTo(string(backend.ForwardPortAlgorithm)),
|
||||||
StickySessions: fi.PtrTo(string(backend.StickySessions)),
|
StickySessions: fi.PtrTo(string(backend.StickySessions)),
|
||||||
ProxyProtocol: fi.PtrTo(string(backend.ProxyProtocol)),
|
ProxyProtocol: fi.PtrTo(string(backend.ProxyProtocol)),
|
||||||
|
LoadBalancer: &LoadBalancer{
|
||||||
|
Name: fi.PtrTo(backend.LB.Name),
|
||||||
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,9 +93,6 @@ func (_ *LBBackend) CheckChanges(actual, expected, changes *LBBackend) error {
|
||||||
if changes.ID != nil {
|
if changes.ID != nil {
|
||||||
return fi.CannotChangeField("ID")
|
return fi.CannotChangeField("ID")
|
||||||
}
|
}
|
||||||
if changes.LBName != nil {
|
|
||||||
return fi.CannotChangeField("Load-balancer name")
|
|
||||||
}
|
|
||||||
if changes.Zone != nil {
|
if changes.Zone != nil {
|
||||||
return fi.CannotChangeField("Zone")
|
return fi.CannotChangeField("Zone")
|
||||||
}
|
}
|
||||||
|
@ -116,9 +100,6 @@ func (_ *LBBackend) CheckChanges(actual, expected, changes *LBBackend) error {
|
||||||
if expected.Name == nil {
|
if expected.Name == nil {
|
||||||
return fi.RequiredField("Name")
|
return fi.RequiredField("Name")
|
||||||
}
|
}
|
||||||
if expected.LBName == nil {
|
|
||||||
return fi.RequiredField("Load-Balancer name")
|
|
||||||
}
|
|
||||||
if expected.Zone == nil {
|
if expected.Zone == nil {
|
||||||
return fi.RequiredField("Zone")
|
return fi.RequiredField("Zone")
|
||||||
}
|
}
|
||||||
|
@ -129,19 +110,6 @@ func (_ *LBBackend) CheckChanges(actual, expected, changes *LBBackend) error {
|
||||||
func (l *LBBackend) RenderScw(t *scaleway.ScwAPITarget, actual, expected, changes *LBBackend) error {
|
func (l *LBBackend) RenderScw(t *scaleway.ScwAPITarget, actual, expected, changes *LBBackend) error {
|
||||||
lbService := t.Cloud.LBService()
|
lbService := t.Cloud.LBService()
|
||||||
|
|
||||||
// We fetch the ID of the LB from its name
|
|
||||||
lbResponse, err := lbService.ListLBs(&lb.ZonedAPIListLBsRequest{
|
|
||||||
Zone: scw.Zone(fi.ValueOf(expected.Zone)),
|
|
||||||
Name: l.LBName,
|
|
||||||
}, scw.WithAllPages())
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("getting load-balancer %s: %w", fi.ValueOf(l.LBName), err)
|
|
||||||
}
|
|
||||||
if lbResponse.TotalCount != 1 {
|
|
||||||
return fmt.Errorf("expected 1 load-balancer, got %d", lbResponse.TotalCount)
|
|
||||||
}
|
|
||||||
lbID := lbResponse.LBs[0].ID
|
|
||||||
|
|
||||||
if actual != nil {
|
if actual != nil {
|
||||||
|
|
||||||
_, err := lbService.UpdateBackend(&lb.ZonedAPIUpdateBackendRequest{
|
_, err := lbService.UpdateBackend(&lb.ZonedAPIUpdateBackendRequest{
|
||||||
|
@ -155,16 +123,14 @@ func (l *LBBackend) RenderScw(t *scaleway.ScwAPITarget, actual, expected, change
|
||||||
ProxyProtocol: lb.ProxyProtocol(fi.ValueOf(expected.ProxyProtocol)),
|
ProxyProtocol: lb.ProxyProtocol(fi.ValueOf(expected.ProxyProtocol)),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("updating back-end for load-balancer %s: %w", fi.ValueOf(actual.LBName), err)
|
return fmt.Errorf("updating back-end for load-balancer %s: %w", fi.ValueOf(actual.LoadBalancer.Name), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected.ID = actual.ID
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
req := &lb.ZonedAPICreateBackendRequest{
|
backendCreated, err := lbService.CreateBackend(&lb.ZonedAPICreateBackendRequest{
|
||||||
Zone: scw.Zone(fi.ValueOf(expected.Zone)),
|
Zone: scw.Zone(fi.ValueOf(expected.Zone)),
|
||||||
LBID: lbID,
|
LBID: fi.ValueOf(expected.LoadBalancer.LBID), // try expected instead of l
|
||||||
Name: fi.ValueOf(expected.Name),
|
Name: fi.ValueOf(expected.Name),
|
||||||
ForwardProtocol: lb.Protocol(fi.ValueOf(expected.ForwardProtocol)),
|
ForwardProtocol: lb.Protocol(fi.ValueOf(expected.ForwardProtocol)),
|
||||||
ForwardPort: fi.ValueOf(expected.ForwardPort),
|
ForwardPort: fi.ValueOf(expected.ForwardPort),
|
||||||
|
@ -178,23 +144,21 @@ func (l *LBBackend) RenderScw(t *scaleway.ScwAPITarget, actual, expected, change
|
||||||
CheckDelay: scw.TimeDurationPtr(1001),
|
CheckDelay: scw.TimeDurationPtr(1001),
|
||||||
},
|
},
|
||||||
ProxyProtocol: lb.ProxyProtocol(fi.ValueOf(expected.ProxyProtocol)),
|
ProxyProtocol: lb.ProxyProtocol(fi.ValueOf(expected.ProxyProtocol)),
|
||||||
}
|
})
|
||||||
|
|
||||||
backendCreated, err := lbService.CreateBackend(req)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("creating back-end for load-balancer %s: %w", fi.ValueOf(expected.LBName), err)
|
return fmt.Errorf("creating back-end for load-balancer %s: %w", fi.ValueOf(expected.LoadBalancer.Name), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected.ID = &backendCreated.ID
|
expected.ID = &backendCreated.ID
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = lbService.WaitForLb(&lb.ZonedAPIWaitForLBRequest{
|
_, err := lbService.WaitForLb(&lb.ZonedAPIWaitForLBRequest{
|
||||||
LBID: lbID,
|
LBID: fi.ValueOf(expected.LoadBalancer.LBID),
|
||||||
Zone: scw.Zone(fi.ValueOf(expected.Zone)),
|
Zone: scw.Zone(fi.ValueOf(expected.Zone)),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("waiting for load-balancer %s: %w", fi.ValueOf(expected.LBName), err)
|
return fmt.Errorf("waiting for load-balancer %s: %w", fi.ValueOf(expected.LoadBalancer.Name), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -25,52 +25,37 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/scaleway"
|
"k8s.io/kops/upup/pkg/fi/cloudup/scaleway"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// +kops:fitask
|
||||||
type LBFrontend struct {
|
type LBFrontend struct {
|
||||||
Name *string
|
Name *string
|
||||||
Lifecycle fi.Lifecycle
|
Lifecycle fi.Lifecycle
|
||||||
|
|
||||||
ID *string
|
ID *string
|
||||||
LBName *string
|
|
||||||
Zone *string
|
Zone *string
|
||||||
InboundPort *int32
|
InboundPort *int32
|
||||||
BackendID *string
|
|
||||||
|
LoadBalancer *LoadBalancer
|
||||||
|
LBBackend *LBBackend
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ fi.CloudupTask = &LBFrontend{}
|
var _ fi.CloudupTask = &LBFrontend{}
|
||||||
var _ fi.CompareWithID = &LBFrontend{}
|
var _ fi.CompareWithID = &LBFrontend{}
|
||||||
var _ fi.HasName = &LBFrontend{}
|
|
||||||
|
|
||||||
func (l *LBFrontend) CompareWithID() *string {
|
func (l *LBFrontend) CompareWithID() *string {
|
||||||
return l.ID
|
return l.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LBFrontend) GetName() *string {
|
|
||||||
return l.Name
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *LBFrontend) Find(context *fi.CloudupContext) (*LBFrontend, error) {
|
func (l *LBFrontend) Find(context *fi.CloudupContext) (*LBFrontend, error) {
|
||||||
cloud := context.T.Cloud.(scaleway.ScwCloud)
|
cloud := context.T.Cloud.(scaleway.ScwCloud)
|
||||||
lbService := cloud.LBService()
|
lbService := cloud.LBService()
|
||||||
|
|
||||||
lbResponse, err := lbService.ListLBs(&lb.ZonedAPIListLBsRequest{
|
|
||||||
Zone: scw.Zone(fi.ValueOf(l.Zone)),
|
|
||||||
Name: l.LBName,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("listing load-balancers: %w", err)
|
|
||||||
}
|
|
||||||
if lbResponse.TotalCount != 1 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
loadBalancer := lbResponse.LBs[0]
|
|
||||||
|
|
||||||
frontendResponse, err := lbService.ListFrontends(&lb.ZonedAPIListFrontendsRequest{
|
frontendResponse, err := lbService.ListFrontends(&lb.ZonedAPIListFrontendsRequest{
|
||||||
Zone: scw.Zone(cloud.Zone()),
|
Zone: scw.Zone(cloud.Zone()),
|
||||||
LBID: loadBalancer.ID,
|
LBID: fi.ValueOf(l.LoadBalancer.LBID),
|
||||||
Name: l.Name,
|
Name: l.Name,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("listing front-ends for load-balancer %s: %w", loadBalancer.ID, err)
|
return nil, fmt.Errorf("listing front-ends for load-balancer %s: %w", fi.ValueOf(l.LoadBalancer.LBID), err)
|
||||||
}
|
}
|
||||||
if frontendResponse.TotalCount != 1 {
|
if frontendResponse.TotalCount != 1 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -81,10 +66,15 @@ func (l *LBFrontend) Find(context *fi.CloudupContext) (*LBFrontend, error) {
|
||||||
Name: fi.PtrTo(frontend.Name),
|
Name: fi.PtrTo(frontend.Name),
|
||||||
Lifecycle: l.Lifecycle,
|
Lifecycle: l.Lifecycle,
|
||||||
ID: fi.PtrTo(frontend.ID),
|
ID: fi.PtrTo(frontend.ID),
|
||||||
LBName: fi.PtrTo(frontend.LB.Name),
|
|
||||||
BackendID: fi.PtrTo(frontend.Backend.ID),
|
|
||||||
Zone: fi.PtrTo(string(frontend.LB.Zone)),
|
Zone: fi.PtrTo(string(frontend.LB.Zone)),
|
||||||
InboundPort: fi.PtrTo(frontend.InboundPort),
|
InboundPort: fi.PtrTo(frontend.InboundPort),
|
||||||
|
LoadBalancer: &LoadBalancer{
|
||||||
|
Name: fi.PtrTo(frontend.LB.Name),
|
||||||
|
},
|
||||||
|
LBBackend: &LBBackend{
|
||||||
|
Name: fi.PtrTo(frontend.Backend.Name),
|
||||||
|
ID: fi.PtrTo(frontend.Backend.ID),
|
||||||
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,22 +90,13 @@ func (_ *LBFrontend) CheckChanges(actual, expected, changes *LBFrontend) error {
|
||||||
if changes.ID != nil {
|
if changes.ID != nil {
|
||||||
return fi.CannotChangeField("ID")
|
return fi.CannotChangeField("ID")
|
||||||
}
|
}
|
||||||
if changes.LBName != nil {
|
|
||||||
return fi.CannotChangeField("Load-balancer name")
|
|
||||||
}
|
|
||||||
if changes.Zone != nil {
|
if changes.Zone != nil {
|
||||||
return fi.CannotChangeField("Zone")
|
return fi.CannotChangeField("Zone")
|
||||||
}
|
}
|
||||||
if changes.BackendID != nil {
|
|
||||||
return fi.CannotChangeField("Back-end ID")
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if expected.Name == nil {
|
if expected.Name == nil {
|
||||||
return fi.RequiredField("Name")
|
return fi.RequiredField("Name")
|
||||||
}
|
}
|
||||||
if expected.LBName == nil {
|
|
||||||
return fi.RequiredField("Load-Balancer name")
|
|
||||||
}
|
|
||||||
if expected.Zone == nil {
|
if expected.Zone == nil {
|
||||||
return fi.RequiredField("Zone")
|
return fi.RequiredField("Zone")
|
||||||
}
|
}
|
||||||
|
@ -126,32 +107,6 @@ func (_ *LBFrontend) CheckChanges(actual, expected, changes *LBFrontend) error {
|
||||||
func (l *LBFrontend) RenderScw(t *scaleway.ScwAPITarget, actual, expected, changes *LBFrontend) error {
|
func (l *LBFrontend) RenderScw(t *scaleway.ScwAPITarget, actual, expected, changes *LBFrontend) error {
|
||||||
lbService := t.Cloud.LBService()
|
lbService := t.Cloud.LBService()
|
||||||
|
|
||||||
// We fetch the ID of the LB from its name
|
|
||||||
lbResponse, err := lbService.ListLBs(&lb.ZonedAPIListLBsRequest{
|
|
||||||
Zone: scw.Zone(fi.ValueOf(expected.Zone)),
|
|
||||||
Name: l.LBName,
|
|
||||||
}, scw.WithAllPages())
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("getting load-balancer %s: %w", fi.ValueOf(l.LBName), err)
|
|
||||||
}
|
|
||||||
if lbResponse.TotalCount != 1 {
|
|
||||||
return fmt.Errorf("expected 1 load-balancer, got %d", lbResponse.TotalCount)
|
|
||||||
}
|
|
||||||
lbID := lbResponse.LBs[0].ID
|
|
||||||
|
|
||||||
// We fetch the ID of the back-end from the load-balancer's ID
|
|
||||||
backendResponse, err := lbService.ListBackends(&lb.ZonedAPIListBackendsRequest{
|
|
||||||
Zone: scw.Zone(fi.ValueOf(expected.Zone)),
|
|
||||||
LBID: lbID,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("listing back-ends for load-balancer %s: %w", lbID, err)
|
|
||||||
}
|
|
||||||
if backendResponse.TotalCount != 1 {
|
|
||||||
return fmt.Errorf("expected 1 load-balancer back-end, got %d", backendResponse.TotalCount)
|
|
||||||
}
|
|
||||||
backendID := backendResponse.Backends[0].ID
|
|
||||||
|
|
||||||
if actual != nil {
|
if actual != nil {
|
||||||
|
|
||||||
_, err := lbService.UpdateFrontend(&lb.ZonedAPIUpdateFrontendRequest{
|
_, err := lbService.UpdateFrontend(&lb.ZonedAPIUpdateFrontendRequest{
|
||||||
|
@ -159,37 +114,35 @@ func (l *LBFrontend) RenderScw(t *scaleway.ScwAPITarget, actual, expected, chang
|
||||||
FrontendID: fi.ValueOf(actual.ID),
|
FrontendID: fi.ValueOf(actual.ID),
|
||||||
Name: fi.ValueOf(actual.Name),
|
Name: fi.ValueOf(actual.Name),
|
||||||
InboundPort: fi.ValueOf(expected.InboundPort),
|
InboundPort: fi.ValueOf(expected.InboundPort),
|
||||||
BackendID: backendID,
|
BackendID: fi.ValueOf(actual.LBBackend.ID),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("updating front-end for load-balancer %s: %w", fi.ValueOf(actual.LBName), err)
|
return fmt.Errorf("updating front-end for load-balancer %s: %w", fi.ValueOf(actual.LoadBalancer.Name), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected.BackendID = &backendID
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
frontendCreated, err := lbService.CreateFrontend(&lb.ZonedAPICreateFrontendRequest{
|
frontendCreated, err := lbService.CreateFrontend(&lb.ZonedAPICreateFrontendRequest{
|
||||||
Zone: scw.Zone(fi.ValueOf(expected.Zone)),
|
Zone: scw.Zone(fi.ValueOf(expected.Zone)),
|
||||||
LBID: lbID,
|
LBID: fi.ValueOf(expected.LoadBalancer.LBID), // try expected instead of l
|
||||||
Name: fi.ValueOf(expected.Name),
|
Name: fi.ValueOf(expected.Name),
|
||||||
InboundPort: fi.ValueOf(expected.InboundPort),
|
InboundPort: fi.ValueOf(expected.InboundPort),
|
||||||
BackendID: backendID,
|
BackendID: fi.ValueOf(expected.LBBackend.ID), // try expected instead of l
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("creating front-end for load-balancer %s: %w", fi.ValueOf(expected.LBName), err)
|
return fmt.Errorf("creating front-end for load-balancer %s: %w", fi.ValueOf(expected.LoadBalancer.Name), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected.ID = &frontendCreated.ID
|
expected.ID = &frontendCreated.ID
|
||||||
expected.BackendID = &backendID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = lbService.WaitForLb(&lb.ZonedAPIWaitForLBRequest{
|
_, err := lbService.WaitForLb(&lb.ZonedAPIWaitForLBRequest{
|
||||||
LBID: lbID,
|
LBID: fi.ValueOf(expected.LoadBalancer.LBID),
|
||||||
Zone: scw.Zone(fi.ValueOf(expected.Zone)),
|
Zone: scw.Zone(fi.ValueOf(expected.Zone)),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("waiting for load-balancer %s: %w", fi.ValueOf(expected.LBName), err)
|
return fmt.Errorf("waiting for load-balancer %s: %w", fi.ValueOf(expected.LoadBalancer.Name), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
//go:build !ignore_autogenerated
|
||||||
|
// +build !ignore_autogenerated
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Code generated by fitask. DO NOT EDIT.
|
||||||
|
|
||||||
|
package scalewaytasks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
|
)
|
||||||
|
|
||||||
|
// LBBackend
|
||||||
|
|
||||||
|
var _ fi.HasLifecycle = &LBBackend{}
|
||||||
|
|
||||||
|
// GetLifecycle returns the Lifecycle of the object, implementing fi.HasLifecycle
|
||||||
|
func (o *LBBackend) GetLifecycle() fi.Lifecycle {
|
||||||
|
return o.Lifecycle
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLifecycle sets the Lifecycle of the object, implementing fi.SetLifecycle
|
||||||
|
func (o *LBBackend) SetLifecycle(lifecycle fi.Lifecycle) {
|
||||||
|
o.Lifecycle = lifecycle
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ fi.HasName = &LBBackend{}
|
||||||
|
|
||||||
|
// GetName returns the Name of the object, implementing fi.HasName
|
||||||
|
func (o *LBBackend) GetName() *string {
|
||||||
|
return o.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// String is the stringer function for the task, producing readable output using fi.TaskAsString
|
||||||
|
func (o *LBBackend) String() string {
|
||||||
|
return fi.CloudupTaskAsString(o)
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
//go:build !ignore_autogenerated
|
||||||
|
// +build !ignore_autogenerated
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Code generated by fitask. DO NOT EDIT.
|
||||||
|
|
||||||
|
package scalewaytasks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
|
)
|
||||||
|
|
||||||
|
// LBFrontend
|
||||||
|
|
||||||
|
var _ fi.HasLifecycle = &LBFrontend{}
|
||||||
|
|
||||||
|
// GetLifecycle returns the Lifecycle of the object, implementing fi.HasLifecycle
|
||||||
|
func (o *LBFrontend) GetLifecycle() fi.Lifecycle {
|
||||||
|
return o.Lifecycle
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLifecycle sets the Lifecycle of the object, implementing fi.SetLifecycle
|
||||||
|
func (o *LBFrontend) SetLifecycle(lifecycle fi.Lifecycle) {
|
||||||
|
o.Lifecycle = lifecycle
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ fi.HasName = &LBFrontend{}
|
||||||
|
|
||||||
|
// GetName returns the Name of the object, implementing fi.HasName
|
||||||
|
func (o *LBFrontend) GetName() *string {
|
||||||
|
return o.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// String is the stringer function for the task, producing readable output using fi.TaskAsString
|
||||||
|
func (o *LBFrontend) String() string {
|
||||||
|
return fi.CloudupTaskAsString(o)
|
||||||
|
}
|
|
@ -953,6 +953,8 @@ type ACL struct {
|
||||||
CreatedAt *time.Time `json:"created_at"`
|
CreatedAt *time.Time `json:"created_at"`
|
||||||
// UpdatedAt: date at which the ACL was last updated
|
// UpdatedAt: date at which the ACL was last updated
|
||||||
UpdatedAt *time.Time `json:"updated_at"`
|
UpdatedAt *time.Time `json:"updated_at"`
|
||||||
|
// Description: description of your ACL ressource
|
||||||
|
Description string `json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ACLAction: acl action
|
// ACLAction: acl action
|
||||||
|
@ -992,6 +994,8 @@ type ACLSpec struct {
|
||||||
Match *ACLMatch `json:"match"`
|
Match *ACLMatch `json:"match"`
|
||||||
// Index: order between your Acls (ascending order, 0 is first acl executed)
|
// Index: order between your Acls (ascending order, 0 is first acl executed)
|
||||||
Index int32 `json:"index"`
|
Index int32 `json:"index"`
|
||||||
|
// Description: description of your ACL ressource
|
||||||
|
Description string `json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backend: backend
|
// Backend: backend
|
||||||
|
@ -3643,6 +3647,8 @@ type ZonedAPICreateACLRequest struct {
|
||||||
Match *ACLMatch `json:"match"`
|
Match *ACLMatch `json:"match"`
|
||||||
// Index: order between your Acls (ascending order, 0 is first acl executed)
|
// Index: order between your Acls (ascending order, 0 is first acl executed)
|
||||||
Index int32 `json:"index"`
|
Index int32 `json:"index"`
|
||||||
|
// Description: description of your ACL ressource
|
||||||
|
Description string `json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateACL: create an ACL for a given frontend
|
// CreateACL: create an ACL for a given frontend
|
||||||
|
@ -3742,6 +3748,8 @@ type ZonedAPIUpdateACLRequest struct {
|
||||||
Match *ACLMatch `json:"match"`
|
Match *ACLMatch `json:"match"`
|
||||||
// Index: order between your Acls (ascending order, 0 is first acl executed)
|
// Index: order between your Acls (ascending order, 0 is first acl executed)
|
||||||
Index int32 `json:"index"`
|
Index int32 `json:"index"`
|
||||||
|
// Description: description of your ACL ressource
|
||||||
|
Description *string `json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateACL: update an ACL
|
// UpdateACL: update an ACL
|
||||||
|
@ -6702,6 +6710,8 @@ type CreateACLRequest struct {
|
||||||
Match *ACLMatch `json:"match"`
|
Match *ACLMatch `json:"match"`
|
||||||
// Index: order between your Acls (ascending order, 0 is first acl executed)
|
// Index: order between your Acls (ascending order, 0 is first acl executed)
|
||||||
Index int32 `json:"index"`
|
Index int32 `json:"index"`
|
||||||
|
// Description: description of your ACL ressource
|
||||||
|
Description string `json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateACL: create an ACL for a given frontend
|
// CreateACL: create an ACL for a given frontend
|
||||||
|
@ -6801,6 +6811,8 @@ type UpdateACLRequest struct {
|
||||||
Match *ACLMatch `json:"match"`
|
Match *ACLMatch `json:"match"`
|
||||||
// Index: order between your Acls (ascending order, 0 is first acl executed)
|
// Index: order between your Acls (ascending order, 0 is first acl executed)
|
||||||
Index int32 `json:"index"`
|
Index int32 `json:"index"`
|
||||||
|
// Description: description of your ACL ressource
|
||||||
|
Description *string `json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateACL: update an ACL
|
// UpdateACL: update an ACL
|
||||||
|
|
Loading…
Reference in New Issue