Skip to content

Commit

Permalink
fix: ssset better logging, add sset, or ssset name (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiGuranIonos authored Jan 21, 2025
1 parent 3ef1684 commit b5932de
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 39 deletions.
6 changes: 3 additions & 3 deletions internal/controller/compute/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (c *externalServer) Update(ctx context.Context, mg resource.Managed) (manag
}
// Attach or Detach Volume
if cr.Spec.ForProvider.VolumeCfg.VolumeID != "" && cr.Spec.ForProvider.VolumeCfg.VolumeID != cr.Status.AtProvider.VolumeID {
c.log.Debug("Update, attaching ", "volume", cr.Spec.ForProvider.VolumeCfg.VolumeID)
c.log.Debug("Update, attaching ", "volume id", cr.Spec.ForProvider.VolumeCfg.VolumeID, "volume name", cr.Spec.ForProvider.Name, "for server name", cr.Spec.ForProvider.Name)
_, apiResponse, err := c.service.AttachVolume(ctx, cr.Spec.ForProvider.DatacenterCfg.DatacenterID, cr.Status.AtProvider.ServerID,
sdkgo.Volume{Id: &cr.Spec.ForProvider.VolumeCfg.VolumeID})
if err != nil {
Expand All @@ -226,10 +226,10 @@ func (c *externalServer) Update(ctx context.Context, mg resource.Managed) (manag
if err = compute.WaitForRequest(ctx, c.service.GetAPIClient(), apiResponse); err != nil {
return managed.ExternalUpdate{}, err
}
c.log.Debug("Update, finished attaching Volume", "volume", cr.Spec.ForProvider.VolumeCfg.VolumeID)
c.log.Debug("Update, finished attaching Volume", "volume", cr.Spec.ForProvider.VolumeCfg.VolumeID, "volume name", cr.Spec.ForProvider.Name, "for server name", cr.Spec.ForProvider.Name)

} else if cr.Spec.ForProvider.VolumeCfg.VolumeID == "" && cr.Status.AtProvider.VolumeID != "" {
c.log.Debug("Update, detaching ", "volume", cr.Status.AtProvider.VolumeID)
c.log.Debug("Update, detaching ", "volume", cr.Status.AtProvider.VolumeID, "for server name", cr.Spec.ForProvider.Name)
apiResponse, err := c.service.DetachVolume(ctx, cr.Spec.ForProvider.DatacenterCfg.DatacenterID,
cr.Status.AtProvider.ServerID, cr.Status.AtProvider.VolumeID)
if err != nil {
Expand Down
21 changes: 10 additions & 11 deletions internal/controller/compute/statefulserverset/lan_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ type kubeLANController struct {
// Create creates a lan CR and waits until in reaches AVAILABLE state
func (k *kubeLANController) Create(ctx context.Context, cr *v1alpha1.StatefulServerSet, lanIndex int) (v1alpha1.Lan, error) {
name := cr.Spec.ForProvider.Lans[lanIndex].Metadata.Name
k.log.Info("Creating LAN", "name", name)
k.log.Info("Creating LAN", "name", name, "ssset", cr.Name)

createLAN := fromStatefulServerSetToLAN(cr, name, lanIndex)
if err := k.kube.Create(ctx, &createLAN); err != nil {
return v1alpha1.Lan{}, err
return v1alpha1.Lan{}, fmt.Errorf("while creating lan %s %w", createLAN.Name, err)
}
if err := kube.WaitForResource(ctx, kube.ResourceReadyTimeout, k.isAvailable, name, cr.Namespace); err != nil {
_ = k.Delete(ctx, name, cr.Namespace)
return v1alpha1.Lan{}, fmt.Errorf("while waiting for LAN to be populated %w ", err)
return v1alpha1.Lan{}, fmt.Errorf("while waiting for LAN to be populated %s %w", name, err)
}
kubeLAN, err := k.Get(ctx, name, cr.Namespace)
if err != nil {
return v1alpha1.Lan{}, err
}
k.log.Info("Finished creating LAN", "name", name)
k.log.Info("Finished creating LAN", "name", name, "ssset", cr.Name)

return *kubeLAN, nil
}
Expand Down Expand Up @@ -84,19 +84,19 @@ func (k *kubeLANController) Update(ctx context.Context, cr *v1alpha1.StatefulSer
return v1alpha1.Lan{}, nil
}

k.log.Info("Updating LAN", "name", name)
k.log.Info("Updating LAN", "name", name, "ssset", cr.Name)

if err := k.kube.Update(ctx, updateKubeLAN); err != nil {
return v1alpha1.Lan{}, err
}
if err := kube.WaitForResource(ctx, kube.ResourceReadyTimeout, k.isAvailable, name, cr.Namespace); err != nil {
return v1alpha1.Lan{}, err
return v1alpha1.Lan{}, fmt.Errorf("while waiting for resource %s to be populated %w ", name, err)
}
updateKubeLAN, err = k.Get(ctx, name, cr.Namespace)
if err != nil {
return v1alpha1.Lan{}, err
}
k.log.Info("Finished updating LAN", "name", name)
k.log.Info("Finished updating LAN", "name", name, "ssset", cr.Name)
return *updateKubeLAN, nil
}

Expand Down Expand Up @@ -128,7 +128,7 @@ func (k *kubeLANController) Delete(ctx context.Context, name, namespace string)
return err
}
if err := k.kube.Delete(ctx, condemnedLAN); err != nil {
return fmt.Errorf("while deleting lan %w", err)
return fmt.Errorf("while deleting lan %s %w", name, err)
}
return kube.WaitForResource(ctx, kube.ResourceReadyTimeout, k.isLANDeleted, condemnedLAN.Name, namespace)
}
Expand Down Expand Up @@ -200,7 +200,7 @@ func fromStatefulServerSetToLAN(cr *v1alpha1.StatefulServerSet, name string, lan

// Ensure - creates a lan if it does not exist
func (k *kubeLANController) Ensure(ctx context.Context, cr *v1alpha1.StatefulServerSet, lanIndex int) error {
k.log.Info("Ensuring LAN", "lanIndex", lanIndex)
k.log.Info("Ensuring LAN", "lanIndex", lanIndex, "ssset", cr.Name)
res := &v1alpha1.LanList{}
if err := k.kube.List(ctx, res, client.MatchingLabels{
fmt.Sprintf(volumeselector.IndexLabel, getSSetName(cr), resourceLAN): strconv.Itoa(lanIndex),
Expand All @@ -212,7 +212,6 @@ func (k *kubeLANController) Ensure(ctx context.Context, cr *v1alpha1.StatefulSer
_, err := k.Create(ctx, cr, lanIndex)
return err
}
k.log.Info("Finished ensuring LAN", "lanIndex", lanIndex)

k.log.Info("Finished ensuring LAN", "lanIndex", lanIndex, "ssset", cr.Name)
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (e *external) observeResourcesUpdateStatus(ctx context.Context, cr *v1alpha
if err != nil {
return false, false, false, err
}
e.log.Info("Observing the StatefulServerSet", "creationLansUpToDate", creationLansUpToDate, "lansUpToDate", lansUpToDate, "creationVolumesUpToDate", creationVolumesUpToDate,
e.log.Info("Observing the StatefulServerSet", "name", cr.Name, "creationLansUpToDate", creationLansUpToDate, "lansUpToDate", lansUpToDate, "creationVolumesUpToDate", creationVolumesUpToDate,
"areVolumesUpToDate", areVolumesUpToDate, "creationSSetUpToDate", creationSSetUpToDate, "isSSetUpToDate", isSSetUpToDate, "creationVSUpToDate", creationVSUpToDate, "areVolumesAvailable", areVolumesAvailable)
areResourcesCreated = creationLansUpToDate && creationVolumesUpToDate && creationSSetUpToDate && creationVSUpToDate
areResourcesUpdated = lansUpToDate && areVolumesUpToDate && isSSetUpToDate
Expand Down Expand Up @@ -328,7 +328,7 @@ func (e *external) Delete(ctx context.Context, mg resource.Managed) (managed.Ext
}

func (e *external) ensureDataVolumes(ctx context.Context, cr *v1alpha1.StatefulServerSet, replicaIndex int) error {
e.log.Info("Ensuring the DataVolumes")
e.log.Info("Ensuring the DataVolumes for ", "name", cr.Name)
for volumeIndex := range cr.Spec.ForProvider.Volumes {
err := e.dataVolumeController.Ensure(ctx, cr, replicaIndex, volumeIndex)
if err != nil {
Expand All @@ -339,7 +339,7 @@ func (e *external) ensureDataVolumes(ctx context.Context, cr *v1alpha1.StatefulS
}

func (e *external) ensureLans(ctx context.Context, cr *v1alpha1.StatefulServerSet) error {
e.log.Info("Ensuring the LANs")
e.log.Info("Ensuring the LANs for", "name", cr.Name)
for lanIndex := range cr.Spec.ForProvider.Lans {
err := e.LANController.Ensure(ctx, cr, lanIndex)
if err != nil {
Expand Down
20 changes: 10 additions & 10 deletions internal/controller/serverset/nic_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func getNicName(resourceName string, replicaIndex, nicIndex, version int) string
// Create creates a NIC CR and waits until in reaches AVAILABLE state
func (k *kubeNicController) Create(ctx context.Context, cr *v1alpha1.ServerSet, serverID, lanName string, replicaIndex, nicIndex, version int) (v1alpha1.Nic, error) {
name := getNicName(cr.Spec.ForProvider.Template.Spec.NICs[nicIndex].Name, replicaIndex, nicIndex, version)
k.log.Info("Creating NIC", "name", name)
k.log.Info("Creating NIC", "name", name, "serverset", cr.Name)
lan := v1alpha1.Lan{}
if err := k.kube.Get(ctx, types.NamespacedName{
Namespace: cr.GetNamespace(),
Expand All @@ -51,19 +51,19 @@ func (k *kubeNicController) Create(ctx context.Context, cr *v1alpha1.ServerSet,
// no NIC found, create one
createNic := k.fromServerSetToNic(cr, name, serverID, lan, replicaIndex, nicIndex, version)
if err := k.kube.Create(ctx, &createNic); err != nil {
return v1alpha1.Nic{}, fmt.Errorf("while creating NIC %w ", err)
return v1alpha1.Nic{}, fmt.Errorf("while creating NIC %s for serverset %s %w ", createNic.Name, cr.Name, err)
}

err := kube.WaitForResource(ctx, kube.ResourceReadyTimeout, k.isAvailable, createNic.Name, cr.Namespace)
if err != nil {
_ = k.Delete(ctx, createNic.Name, cr.Namespace)
return v1alpha1.Nic{}, fmt.Errorf("while waiting for NIC to be populated %w ", err)
return v1alpha1.Nic{}, fmt.Errorf("while waiting for NIC name %s to be populated for serverset %s %w ", createNic.Name, cr.Name, err)
}
createdNic, err := k.Get(ctx, createNic.Name, cr.Namespace)
if err != nil {
return v1alpha1.Nic{}, fmt.Errorf("while getting NIC %w ", err)
return v1alpha1.Nic{}, fmt.Errorf("while getting NIC name %s for serverset %s %w ", createNic.Name, cr.Name, err)
}
k.log.Info("Finished creating NIC", "name", name)
k.log.Info("Finished creating NIC", "name", name, "serverset", cr.Name)
return *createdNic, nil
}

Expand Down Expand Up @@ -119,14 +119,14 @@ func (k *kubeNicController) isNicDeleted(ctx context.Context, name, namespace st

// Delete - deletes the nic k8s client and waits until it is deleted
func (k *kubeNicController) Delete(ctx context.Context, name, namespace string) error {
condemnedVolume, err := k.Get(ctx, name, namespace)
condemnedNIC, err := k.Get(ctx, name, namespace)
if err != nil {
return err
}
if err := k.kube.Delete(ctx, condemnedVolume); err != nil {
if err := k.kube.Delete(ctx, condemnedNIC); err != nil {
return err
}
return kube.WaitForResource(ctx, kube.ResourceReadyTimeout, k.isNicDeleted, condemnedVolume.Name, namespace)
return kube.WaitForResource(ctx, kube.ResourceReadyTimeout, k.isNicDeleted, condemnedNIC.Name, namespace)
}

func (k *kubeNicController) fromServerSetToNic(cr *v1alpha1.ServerSet, name, serverID string, lan v1alpha1.Lan, replicaIndex, nicIndex, version int) v1alpha1.Nic {
Expand Down Expand Up @@ -176,7 +176,7 @@ func (k *kubeNicController) fromServerSetToNic(cr *v1alpha1.ServerSet, name, ser

// EnsureNICs - creates NICS if they do not exist
func (k *kubeNicController) EnsureNICs(ctx context.Context, cr *v1alpha1.ServerSet, replicaIndex, version int) error {
k.log.Info("Ensuring NICs", "index", replicaIndex, "version", version)
k.log.Info("Ensuring NICs", "index", replicaIndex, "version", version, "serverset", cr.Name)
res := &v1alpha1.ServerList{}
if err := listResFromSSetWithIndexAndVersion(ctx, k.kube, cr.GetName(), ResourceServer, replicaIndex, version, res); err != nil {
return err
Expand All @@ -190,7 +190,7 @@ func (k *kubeNicController) EnsureNICs(ctx context.Context, cr *v1alpha1.ServerS
}
}
}
k.log.Info("Finished ensuring NICs", "index", replicaIndex, "version", version)
k.log.Info("Finished ensuring NICs", "index", replicaIndex, "version", version, "serverset", cr.Name)

return nil
}
Expand Down
16 changes: 8 additions & 8 deletions internal/controller/serverset/server_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ type kubeServerController struct {
// Create creates a server CR and waits until in reaches AVAILABLE state
func (k *kubeServerController) Create(ctx context.Context, cr *v1alpha1.ServerSet, replicaIndex, version int) (v1alpha1.Server, error) {
createServer := fromServerSetToServer(cr, replicaIndex, version)
k.log.Info("Creating Server", "name", createServer.Name)
k.log.Info("Creating Server", "name", createServer.Name, "serverset", cr.Name)

if err := k.kube.Create(ctx, &createServer); err != nil {
return v1alpha1.Server{}, fmt.Errorf("while creating Server %w ", err)
return v1alpha1.Server{}, fmt.Errorf("while creating Server for serverset %s %w", cr.Name, err)
}
if err := kube.WaitForResource(ctx, kube.ResourceReadyTimeout, k.isAvailable, createServer.Name, cr.Namespace); err != nil {
_ = k.Delete(ctx, createServer.Name, cr.Namespace)
return v1alpha1.Server{}, fmt.Errorf("while waiting for Server to be populated %w ", err)
return v1alpha1.Server{}, fmt.Errorf("while waiting for Server to be populated in serverset %s %w ", cr.Name, err)
}
createdServer, err := k.Get(ctx, createServer.Name, cr.Namespace)
if err != nil {
return v1alpha1.Server{}, fmt.Errorf("while getting created Server %w ", err)
return v1alpha1.Server{}, fmt.Errorf("while getting created Server for serverset %s %w", cr.Name, err)
}
k.log.Info("Finished creating Server", "name", createServer.Name)
k.log.Info("Finished creating Server", "name", createServer.Name, "serverset", cr.Name)

return *createdServer, nil
}
Expand Down Expand Up @@ -93,7 +93,7 @@ func (k *kubeServerController) Delete(ctx context.Context, name, namespace strin
return err
}
if err := k.kube.Delete(ctx, condemnedServer); err != nil {
return fmt.Errorf("error deleting server %w", err)
return fmt.Errorf("error deleting server name %s %w", name, err)
}
return kube.WaitForResource(ctx, kube.ResourceReadyTimeout, k.isServerDeleted, condemnedServer.Name, namespace)
}
Expand Down Expand Up @@ -164,7 +164,7 @@ func (k *kubeServerController) Ensure(ctx context.Context, cr *v1alpha1.ServerSe
}
servers := res.Items
if len(servers) > 0 {
k.log.Info("Server already exists", "name", servers[0].Name)
k.log.Info("Server already exists", "name", servers[0].Name, "serverset", cr.Name)
return nil
}

Expand All @@ -173,7 +173,7 @@ func (k *kubeServerController) Ensure(ctx context.Context, cr *v1alpha1.ServerSe
return err
}

k.log.Info("Finished ensuring Server", "index", replicaIndex, "version", version)
k.log.Info("Finished ensuring Server", "index", replicaIndex, "version", version, "serverset", cr.Name)

return nil
}
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/serverset/serverset.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (e *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
areNICsCreated := len(nics) == crExpectedNoOfNICs

// at the moment we do not check that fields of nics are updated, because nic fields are immutable
e.log.Info("Observing the ServerSet", "areServersUpToDate", areServersUpToDate, "areBootVolumesUpToDate", areBootVolumesUpToDate, "areServersCreated",
e.log.Info("Observing the ServerSet", "name", cr.Name, "areServersUpToDate", areServersUpToDate, "areBootVolumesUpToDate", areBootVolumesUpToDate, "areServersCreated",
areServersCreated, "areBootVolumesCreated", areBootVolumesCreated, "areNICsCreated", areNICsCreated, "areServersAvailable", areServersAvailable, "areBootVolumesAvailable", areBootVolumesAvailable)
if areServersAvailable && areBootVolumesAvailable {
cr.SetConditions(xpv1.Available())
Expand Down Expand Up @@ -281,7 +281,7 @@ func fetchRole(ctx context.Context, e *external, sset v1alpha1.ServerSet, replic
if sset.Spec.ForProvider.IdentityConfigMap.Namespace == "" ||
sset.Spec.ForProvider.IdentityConfigMap.Name == "" ||
sset.Spec.ForProvider.IdentityConfigMap.KeyName == "" {
e.log.Info("no identity configmap values provided, setting role based on replica index only")
e.log.Info("no identity configmap values provided, setting role based on replica index only for", "serverset name", sset.Name)
if replicaIndex == 0 {
return v1alpha1.Active
}
Expand All @@ -293,7 +293,7 @@ func fetchRole(ctx context.Context, e *external, sset v1alpha1.ServerSet, replic
cfgLease := &v1.ConfigMap{}
err := e.kube.Get(ctx, client.ObjectKey{Namespace: namespace, Name: name}, cfgLease)
if err != nil {
e.log.Info("error fetching config lease, will default to PASSIVE role", "error", err)
e.log.Info("error fetching config lease, will default to PASSIVE role", "serverset name", sset.Name, "error", err)
return v1alpha1.Passive
}

Expand Down
5 changes: 4 additions & 1 deletion internal/controller/volumeselector/volumeselector.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ func (c *externalVolumeselector) Observe(ctx context.Context, mg resource.Manage

func (c *externalVolumeselector) Create(ctx context.Context, mg resource.Managed) (managed.ExternalCreation, error) {
cr, ok := mg.(*v1alpha1.Volumeselector)
c.log.Debug("Create volumeselector", "name", cr.Name, "serverset", cr.Spec.ForProvider.ServersetName)

if !ok {
return managed.ExternalCreation{}, errors.New(errNotVolumeSelector)
}
Expand All @@ -154,6 +156,7 @@ func (c *externalVolumeselector) Create(ctx context.Context, mg resource.Managed

func (c *externalVolumeselector) Update(ctx context.Context, mg resource.Managed) (managed.ExternalUpdate, error) {
cr, ok := mg.(*v1alpha1.Volumeselector)
c.log.Debug("Update volumeselector ", "name", cr.Name, "serverset", cr.Spec.ForProvider.ServersetName)
if !ok {
return managed.ExternalUpdate{}, errors.New(errNotVolumeSelector)
}
Expand Down Expand Up @@ -244,7 +247,7 @@ func (c *externalVolumeselector) areVolumesAndServersReady(volumeList v1alpha1.V
return false
}
if serverList.Items[0].Status.AtProvider.ServerID == "" {
c.log.Info("Server does not have ID")
c.log.Info("Server does not have ID", "name", serverList.Items[0].Name)
return false
}

Expand Down

0 comments on commit b5932de

Please sign in to comment.