Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add amphora image tag configuration #383

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion controllers/amphoracontroller_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func (r *OctaviaAmphoraControllerReconciler) reconcileNormal(ctx context.Context

defaultFlavorID, err := amphoracontrollers.EnsureFlavors(ctx, instance, &r.Log, helper)
if err != nil {
return ctrl.Result{}, err
return ctrl.Result{RequeueAfter: time.Duration(60) * time.Second}, nil
}
r.Log.Info(fmt.Sprintf("Using default flavor \"%s\"", defaultFlavorID))

Expand Down
49 changes: 32 additions & 17 deletions pkg/amphoracontrollers/flavors.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type OctaviaFlavors struct {
// FlavorProfileData -
type FlavorProfileData struct {
ComputeFlavorID string `json:"compute_flavor"`
AmpImageTag string `json:"amp_image_tag"`
}

var (
Expand Down Expand Up @@ -77,11 +78,11 @@ func getAmphoraFlavors(computeClient *gophercloud.ServiceClient) (map[string]com
}
allPages, err := computeflavors.ListDetail(computeClient, listOpts).AllPages()
if err != nil {
return nil, err
return nil, fmt.Errorf("error listing compute flavors: %w", err)
}
allFlavors, err := computeflavors.ExtractFlavors(allPages)
if err != nil {
return nil, err
return nil, fmt.Errorf("error extracting compute flavors: %w", err)
}
amphoraFlavors := make(map[string]computeflavors.Flavor)
for _, flavor := range allFlavors {
Expand All @@ -96,11 +97,11 @@ func getOctaviaFlavorProfiles(lbClient *gophercloud.ServiceClient) (map[string]f
listOpts := flavorprofiles.ListOpts{}
allPages, err := flavorprofiles.List(lbClient, listOpts).AllPages()
if err != nil {
return nil, err
return nil, fmt.Errorf("error listing flavor profiles: %w", err)
}
allFlavorProfiles, err := flavorprofiles.ExtractFlavorProfiles(allPages)
if err != nil {
return nil, err
return nil, fmt.Errorf("error extracting flavor profiles: %w", err)
}
flavorProfiles := make(map[string]flavorprofiles.FlavorProfile)
for _, flavorProfile := range allFlavorProfiles {
Expand All @@ -113,11 +114,11 @@ func getOctaviaFlavors(lbClient *gophercloud.ServiceClient) (map[string]flavors.
listOpts := flavors.ListOpts{}
allPages, err := flavors.List(lbClient, listOpts).AllPages()
if err != nil {
return nil, err
return nil, fmt.Errorf("error listing flavors: %w", err)
}
allFlavors, err := flavors.ExtractFlavors(allPages)
if err != nil {
return nil, err
return nil, fmt.Errorf("error extracting flavors: %w", err)
}
flavors := make(map[string]flavors.Flavor)
for _, flavor := range allFlavors {
Expand All @@ -129,17 +130,17 @@ func getOctaviaFlavors(lbClient *gophercloud.ServiceClient) (map[string]flavors.
func ensureFlavors(osclient *openstack.OpenStack, log *logr.Logger, instance *octaviav1.OctaviaAmphoraController) (string, error) {
computeClient, err := octavia.GetComputeClient(osclient)
if err != nil {
return "", err
return "", fmt.Errorf("error getting compute client: %w", err)
}

lbClient, err := octavia.GetLoadBalancerClient(osclient)
if err != nil {
return "", err
return "", fmt.Errorf("error getting loadbalancer client: %w", err)
}

amphoraFlavors, err := getAmphoraFlavors(computeClient)
if err != nil {
return "", err
return "", fmt.Errorf("error getting amphora flavors: %w", err)
}

isPublic := false
Expand Down Expand Up @@ -188,7 +189,7 @@ func ensureFlavors(osclient *openstack.OpenStack, log *logr.Logger, instance *oc
log.Info(fmt.Sprintf("Creating Amphora flavor \"%s\"", flavorOpts.Name))
flavor, err := computeflavors.Create(computeClient, flavorOpts).Extract()
if err != nil {
return "", err
return "", fmt.Errorf("error creating amphora flavor \"%s\": %w", flavorOpts.Name, err)
}
amphoraFlavors[flavorOpts.Name] = *flavor
if idx == 0 {
Expand All @@ -200,14 +201,15 @@ func ensureFlavors(osclient *openstack.OpenStack, log *logr.Logger, instance *oc
// Get Octavia FlavorProfiles and Flavors
flavorProfileMap, err := getOctaviaFlavorProfiles(lbClient)
if err != nil {
return "", err
return "", fmt.Errorf("error getting flavor profiles: %w", err)
}

flavorMap, err := getOctaviaFlavors(lbClient)
if err != nil {
return "", err
return "", fmt.Errorf("error getting flavors: %w", err)
}

flavorSuccess := false
for _, flavorOpts := range flavorsCreateOpts {
// Create FlavorProfiles if they don't exist

Expand All @@ -217,6 +219,11 @@ func ensureFlavors(osclient *openstack.OpenStack, log *logr.Logger, instance *oc
flavorProfileData := FlavorProfileData{
ComputeFlavorID: amphoraFlavors[flavorOpts.Name].ID,
}

if amphoraFlavors[flavorOpts.Name].VCPUs > 1 {
flavorProfileData.AmpImageTag = octavia.AmphoraImageVertTag
}

fpDataJSON, err := json.Marshal(flavorProfileData)
if err != nil {
return "", err
Expand All @@ -230,7 +237,12 @@ func ensureFlavors(osclient *openstack.OpenStack, log *logr.Logger, instance *oc
log.Info(fmt.Sprintf("Creating Octavia flavor profile \"%s\"", flavorProfileCreateOpts.Name))
fp, err := flavorprofiles.Create(lbClient, flavorProfileCreateOpts).Extract()
if err != nil {
return "", err
log.Info(fmt.Sprintf("Warning: Could not create flavor profile. "+
"Amphora image might be missing or not "+
"tagged correctly. Skipping configuration of octavia "+
"flavor profile %s and octavia flavor %s.",
flavorProfileCreateOpts.Name, name))
continue
}
flavorProfileMap[fp.Name] = *fp
}
Expand All @@ -246,11 +258,14 @@ func ensureFlavors(osclient *openstack.OpenStack, log *logr.Logger, instance *oc
log.Info(fmt.Sprintf("Creating Octavia flavor \"%s\"", flavorCreateOpts.Name))
_, err := flavors.Create(lbClient, flavorCreateOpts).Extract()
if err != nil {
return "", err
return "", fmt.Errorf("error creating flavor \"%s\": %w", flavorCreateOpts.Name, err)
}
}
flavorSuccess = true
}
if !flavorSuccess {
return "", fmt.Errorf("none of the Octavia flavors could be configured")
}

return defaultFlavorID, nil
}

Expand All @@ -260,12 +275,12 @@ func ensureFlavors(osclient *openstack.OpenStack, log *logr.Logger, instance *oc
func EnsureFlavors(ctx context.Context, instance *octaviav1.OctaviaAmphoraController, log *logr.Logger, helper *helper.Helper) (string, error) {
osclient, err := octavia.GetOpenstackClient(ctx, instance.Namespace, helper)
if err != nil {
return "", fmt.Errorf("Error while getting a service client when creating flavors: %w", err)
return "", fmt.Errorf("error while getting a service client when creating flavors: %w", err)
}

defaultNovaFlavorID, err := ensureFlavors(osclient, log, instance)
if err != nil {
return "", fmt.Errorf("Error while creating flavors: %w", err)
return "", fmt.Errorf("error while creating flavors: %w", err)
}

return defaultNovaFlavorID, nil
Expand Down
Loading