Change NodePort to NodePorts
- Addded Finalize entry point for Service - Services Namespace named Sip.Spec.Config.ClusteName is createdd durign SIPCluster deployment - Services Namespace is deleted dring SIPCluster deletion - Some WIP with Servicee Specific flows - Change Sample SIPCluster to be NodePorts instead of NodePort
This commit is contained in:
@@ -15,10 +15,14 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
airshipv1 "sipcluster/pkg/api/v1"
|
||||
airshipvms "sipcluster/pkg/vbmh"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
|
||||
@@ -30,8 +34,9 @@ import (
|
||||
// Validate : will make sure that the deployment is successfull
|
||||
type InfrastructureService interface {
|
||||
//
|
||||
Deploy(*airshipvms.MachineList, client.Client) error
|
||||
Deploy(airshipv1.SIPCluster, *airshipvms.MachineList, client.Client) error
|
||||
Validate() error
|
||||
Finalize(airshipv1.SIPCluster, client.Client) error
|
||||
}
|
||||
|
||||
// Generic Service Factory
|
||||
@@ -40,16 +45,46 @@ type Service struct {
|
||||
config airshipv1.InfraConfig
|
||||
}
|
||||
|
||||
func (s *Service) Deploy(machines *airshipvms.MachineList, c client.Client) error {
|
||||
func (s *Service) Deploy(sip airshipv1.SIPCluster, machines *airshipvms.MachineList, c client.Client) error {
|
||||
// do something, might decouple this a bit
|
||||
// If the serviucces are defined as Helm Chart , then deploy might be simply
|
||||
|
||||
//. Lets make sure that teh namespace is in pace.
|
||||
// will be called the name of the cluster.
|
||||
s.createNS(sip.Spec.Config.ClusterName, c)
|
||||
// Take the data from teh appropriate Machines
|
||||
// Prepare the Config
|
||||
fmt.Printf("Deploy Service:%v \n", s.serviceName)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) createNS(serviceNamespaceName string, c client.Client) error {
|
||||
// Get Namespace
|
||||
// If not foundn then ccreate it
|
||||
ns := &corev1.Namespace{}
|
||||
// c is a created client.
|
||||
err := c.Get(context.Background(), client.ObjectKey{
|
||||
Name: serviceNamespaceName,
|
||||
}, ns)
|
||||
|
||||
if err != nil {
|
||||
serviceNamespace := &corev1.Namespace{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
APIVersion: corev1.SchemeGroupVersion.String(),
|
||||
Kind: "Namespace",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: serviceNamespaceName,
|
||||
},
|
||||
}
|
||||
if err := c.Create(context.TODO(), serviceNamespace); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
func (s *Service) Validate() error {
|
||||
// do something, might decouple this a bit
|
||||
fmt.Printf("Validate Service:%v \n", s.serviceName)
|
||||
@@ -58,6 +93,28 @@ func (s *Service) Validate() error {
|
||||
|
||||
}
|
||||
|
||||
func (s *Service) Finalize(sip airshipv1.SIPCluster, c client.Client) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func FinalizeCommon(sip airshipv1.SIPCluster, c client.Client) error {
|
||||
serviceNamespace := &corev1.Namespace{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
APIVersion: corev1.SchemeGroupVersion.String(),
|
||||
Kind: "Namespace",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: sip.Spec.Config.ClusterName,
|
||||
},
|
||||
}
|
||||
if err := c.Delete(context.TODO(), serviceNamespace); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
// Service Factory
|
||||
func NewService(infraName airshipv1.InfraService, infraCfg airshipv1.InfraConfig) (InfrastructureService, error) {
|
||||
if infraName == airshipv1.LoadBalancerService {
|
||||
|
||||
@@ -15,13 +15,41 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
airshipv1 "sipcluster/pkg/api/v1"
|
||||
airshipvms "sipcluster/pkg/vbmh"
|
||||
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
|
||||
type LoadBalancer struct {
|
||||
Service
|
||||
}
|
||||
|
||||
func (l *LoadBalancer) Deploy(sip airshipv1.SIPCluster, machines *airshipvms.MachineList, c client.Client) error {
|
||||
// do something, might decouple this a bit
|
||||
// If the serviucces are defined as Helm Chart , then deploy might be simply
|
||||
|
||||
// Take the data from teh appropriate Machines
|
||||
// Prepare the Config
|
||||
l.Service.Deploy(sip, machines, c)
|
||||
err := l.Prepare(sip, machines, c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LoadBalancer) Prepare(sip airshipv1.SIPCluster, machines *airshipvms.MachineList, c client.Client) error {
|
||||
fmt.Printf("%s.Prepare machines:%s \n", l.Service.serviceName, machines)
|
||||
for _, machine := range machines.Vbmhs {
|
||||
if machine.VmRole == airshipv1.VmMaster {
|
||||
fmt.Printf("%s.Prepare for machine:%s ip is %s\n", l.Service.serviceName, machine, machine.Data.IpOnInterface[sip.Spec.InfraServices[l.Service.serviceName].NodeInterface])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func newLoadBalancer(infraCfg airshipv1.InfraConfig) InfrastructureService {
|
||||
return &LoadBalancer{
|
||||
Service: Service{
|
||||
|
||||
Reference in New Issue
Block a user