sip/pkg/services/set.go
Sean Eagan 44ee037f5b Remove VM assumption from API
This removes references to "vm", "vino", and "vbmh" in the API and
replaces them with "bmh" since at least the existing functionality of
SIP is applicable to any BMH, not just those backed by vino/VMs.
If/when we add functionality specific to VM nodes, the API for those
features should be named/documented accordingly.

This also updates BMH scheduling to support arbitrary label selectors [0].

[0]: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#resources-that-support-set-based-requirements

Closes: #8
Closes: #9
Change-Id: I105fe3dc854c032c755997c47c24997a03cd65e6
2021-03-15 15:40:49 -05:00

106 lines
2.6 KiB
Go

/*
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
https://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.
*/
package services
import (
"context"
"github.com/go-logr/logr"
apierror "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
airshipv1 "sipcluster/pkg/api/v1"
bmh "sipcluster/pkg/bmh"
)
// InfraService generalizes inftracture services
type InfraService interface {
Deploy() error
Finalize() error
}
// ServiceSet provides access to infrastructure services
type ServiceSet struct {
logger logr.Logger
sip airshipv1.SIPCluster
machines *bmh.MachineList
client client.Client
}
// NewServiceSet returns new instance of ServiceSet
func NewServiceSet(
logger logr.Logger,
sip airshipv1.SIPCluster,
machines *bmh.MachineList,
client client.Client) ServiceSet {
logger = logger.WithValues("SIPCluster", types.NamespacedName{Name: sip.GetNamespace(), Namespace: sip.GetName()})
return ServiceSet{
logger: logger,
sip: sip,
client: client,
machines: machines,
}
}
func (ss ServiceSet) Finalize() error {
return nil
}
// ServiceList returns all services defined in Set
func (ss ServiceSet) ServiceList() ([]InfraService, error) {
serviceList := []InfraService{}
services := ss.sip.Spec.Services
for _, svc := range services.LoadBalancer {
serviceList = append(serviceList,
newLB(ss.sip.GetName(),
ss.sip.GetNamespace(),
ss.logger,
svc,
ss.machines,
ss.client))
}
for _, svc := range services.Auth {
return nil, ErrInfraServiceNotSupported{svc}
}
for _, svc := range services.JumpHost {
serviceList = append(serviceList,
newJumpHost(ss.sip.GetName(),
ss.sip.GetNamespace(),
ss.logger,
svc,
ss.machines,
ss.client))
}
return serviceList, nil
}
func applyRuntimeObject(key client.ObjectKey, obj client.Object, c client.Client) error {
ctx := context.Background()
switch err := c.Get(ctx, key, obj); {
case apierror.IsNotFound(err):
return c.Create(ctx, obj)
case err == nil:
return c.Update(ctx, obj)
default:
return err
}
}
func int32Ptr(i int32) *int32 { return &i }
func int64Ptr(i int64) *int64 { return &i }