Skip to content

Commit

Permalink
make ci happy
Browse files Browse the repository at this point in the history
  • Loading branch information
stuggi committed Apr 14, 2023
1 parent e44a7d1 commit 9778447
Show file tree
Hide file tree
Showing 36 changed files with 73 additions and 206 deletions.
26 changes: 0 additions & 26 deletions api/shared/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ const (
CommonCondReasonServiceNotFound ConditionReason = "ServiceNotFound"
)

//
// Client
//
const (
//
// condition reasones
Expand Down Expand Up @@ -128,9 +126,7 @@ const (
OsClientCondReasonPodMissing ConditionReason = "OpenStackClientPodMissing"
)

//
// ConfigGenerator
//
const (
//
// condition types
Expand Down Expand Up @@ -195,9 +191,7 @@ const (
ConfigGeneratorCondReasonClusterServiceIPError ConditionReason = "ClusterServiceIPError"
)

//
// BaremetalSet
//
const (
// BaremetalSetCondTypeEmpty - special state for 0 requested BaremetalHosts and 0 already provisioned
BaremetalSetCondTypeEmpty ConditionType = "Empty"
Expand Down Expand Up @@ -261,9 +255,7 @@ const (
BaremetalSetCondReasonVirtualMachineCountZero ConditionReason = "BaremetalHostCountZero"
)

//
// ControlPlane
//
const (
// ControlPlaneEmpty - special state for 0 requested VMs and 0 already provisioned
ControlPlaneEmpty ConditionType = "Empty"
Expand Down Expand Up @@ -300,9 +292,7 @@ const (
ControlPlaneReasonDeploymentSSHKeysSecretCreateOrUpdateError ConditionReason = "DeploymentSSHKeysSecretCreateOrUpdateError"
)

//
// Deploy
//
const (
//
// condition types
Expand Down Expand Up @@ -337,9 +327,7 @@ const (
DeployCondReasonConfigCreate ConditionReason = "ConfigCreate"
)

//
// EphemeralHeat
//
const (
//
// condition reasons
Expand All @@ -365,9 +353,7 @@ const (
EphemeralHeatReady ConditionReason = "EphemeralHeatReady"
)

//
// IPSet
//
const (
//
// condition reasones
Expand All @@ -383,9 +369,7 @@ const (
IPSetCondReasonCreated ConditionReason = "OpenStackIPSetCreated"
)

//
// MACAddress
//
const (
//
// condition types
Expand Down Expand Up @@ -418,9 +402,7 @@ const (
MACCondReasonMACNotFound ConditionReason = "OpenStackMACNotFound"
)

//
// Net
//
const (
//
// condition types
Expand Down Expand Up @@ -449,9 +431,7 @@ const (
NetCondReasonNetNotFound ConditionReason = "OpenStackNetNotFound"
)

//
// NetAttach
//
const (
//
// condition types
Expand All @@ -478,9 +458,7 @@ const (
NetAttachCondReasonCreateError ConditionReason = "OpenStackNetAttachCreateError"
)

//
// NetConfig
//
const (
// NetConfigWaiting - the network configuration is blocked by prerequisite objects
NetConfigWaiting ConditionType = "Waiting"
Expand All @@ -505,9 +483,7 @@ const (
NetConfigCondReasonIPReservation ConditionReason = "IPReservationCreated"
)

//
// ProvisionServer
//
const (
// ProvisionServerCondTypeWaiting - something else is causing the OpenStackProvisionServer to wait
ProvisionServerCondTypeWaiting ConditionType = "Waiting"
Expand Down Expand Up @@ -548,9 +524,7 @@ const (
OpenStackProvisionServerCondReasonCreated ConditionReason = "OpenStackProvisionServerCreated"
)

//
// VMSet
//
const (
//
// condition types
Expand Down
4 changes: 2 additions & 2 deletions api/shared/osp.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const (
)

// GetOSPVersion - returns unified ospdirectorv1beta1.OSPVersion for upstream/downstream version
// - TemplateVersion16_2 for eitner 16.2 or upstream train
// - TemplateVersion17_0 for eitner 17.0 or upstream wallaby
// - TemplateVersion16_2 for eitner 16.2 or upstream train
// - TemplateVersion17_0 for eitner 17.0 or upstream wallaby
func GetOSPVersion(parsedVersion string) (OSPVersion, error) {
switch parsedVersion {
case string(TemplateVersionTrain):
Expand Down
2 changes: 0 additions & 2 deletions api/v1beta1/common_openstackcontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
)

//
// GetControlPlane - Get OSP ControlPlane CR where e.g. the status information has the
// OSP version: controlPlane.Status.OSPVersion
// FIXME: We assume there is only one ControlPlane CR for now (enforced by webhook), but this might need to change
//
func GetControlPlane(
c client.Client,
obj metav1.Object,
Expand Down
6 changes: 0 additions & 6 deletions api/v1beta1/common_openstacknet.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

//
// AddOSNetNameLowerLabels - add osnetcfg CR label reference which is used in
// the in the osnetcfg controller to watch this resource and reconcile
//
func AddOSNetNameLowerLabels(
log logr.Logger,
labels map[string]string,
Expand Down Expand Up @@ -85,10 +83,8 @@ func AddOSNetNameLowerLabels(
return labels
}

//
// AddOSNetConfigRefLabel - add osnetcfg CR label reference which is used in
// the in the osnetcfg controller to watch this resource and reconcile
//
func AddOSNetConfigRefLabel(
c client.Client,
namespace string,
Expand Down Expand Up @@ -201,9 +197,7 @@ func GetOpenStackNetsMapWithLabel(
return osNetMap, nil
}

//
// GetOsNetCfg -
//
func GetOsNetCfg(
c client.Client,
namespace string,
Expand Down
2 changes: 0 additions & 2 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ type HostStatus struct {
NetworkDataSecretName string `json:"networkDataSecretName"`
}

//
// SyncIPsetStatus - sync relevant information from IPSet to CR status
//
func SyncIPsetStatus(
cond *shared.Condition,
instanceStatus map[string]HostStatus,
Expand Down
2 changes: 0 additions & 2 deletions api/v1beta1/openstackdeploy_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,8 @@ func (r *OpenStackDeploy) ValidateDelete() error {
return nil
}

//
// Validates all NNCPs created by the used osnetcfg to be in condition.Reason == nmstateshared.NodeNetworkConfigurationPolicyConditionSuccessfullyConfigured.
// If not, stop deployment. User can overwrite this via parameter spec.SkipNNCPValidation: true
//
func (r *OpenStackDeploy) validateNNCP() error {

// 1) get the osctlplane of the namespace (right now there can only be one)
Expand Down
2 changes: 0 additions & 2 deletions api/v1beta2/common_openstackcontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
)

//
// GetControlPlane - Get OSP ControlPlane CR where e.g. the status information has the
// OSP version: controlPlane.Status.OSPVersion
// FIXME: We assume there is only one ControlPlane CR for now (enforced by webhook), but this might need to change
//
func GetControlPlane(
c client.Client,
obj metav1.Object,
Expand Down
2 changes: 0 additions & 2 deletions api/v1beta2/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ type HostStatus struct {
NetworkDataSecretName string `json:"networkDataSecretName"`
}

//
// SyncIPsetStatus - sync relevant information from IPSet to CR status
//
func SyncIPsetStatus(
cond *shared.Condition,
instanceStatus map[string]HostStatus,
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta2/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ limitations under the License.
*/

// Package v1beta2 contains API Schema definitions for the osp-director v1beta2 API group
//+kubebuilder:object:generate=true
//+groupName=osp-director.openstack.org
// +kubebuilder:object:generate=true
// +groupName=osp-director.openstack.org
package v1beta2

import (
Expand Down
14 changes: 7 additions & 7 deletions controllers/openstackbaremetalset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1235,10 +1235,12 @@ func (r *OpenStackBaremetalSetReconciler) baremetalHostCleanup(
return nil
}

/* deleteOwnerRefLabeledObjects - cleans up namespaced objects outside the default namespace
using the owner reference labels added.
List of objects which get cleaned:
- user-data secret, openshift-machine-api namespace
/*
deleteOwnerRefLabeledObjects - cleans up namespaced objects outside the default namespace
using the owner reference labels added.
List of objects which get cleaned:
- user-data secret, openshift-machine-api namespace
*/
func (r *OpenStackBaremetalSetReconciler) deleteOwnerRefLabeledObjects(
ctx context.Context,
Expand Down Expand Up @@ -1305,9 +1307,7 @@ func (r *OpenStackBaremetalSetReconciler) getPasswordSecret(
return passwordSecret, ctrl.Result{}, nil
}

//
// check/update instance status for annotated for deletion marked BMs
//
// check/update instance status for annotated for deletion marked BMs
func (r *OpenStackBaremetalSetReconciler) checkBMHsAnnotatedForDeletion(
ctx context.Context,
instance *ospdirectorv1beta1.OpenStackBaremetalSet,
Expand Down
25 changes: 18 additions & 7 deletions controllers/openstackclient_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ package controllers

import (
"context"
"errors"
"fmt"
"time"

"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/api/equality"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -586,8 +588,12 @@ func (r *OpenStackClientReconciler) podCreateOrUpdate(
}

if imageUpdate && isPodUpdate {
// init container image is mutable but does nothing so force a delete
return &common.ForbiddenPodSpecChangeError{Field: "Spec.InitContainers[0].Image"}
// init container image is mutable but does nothing so force a delete by triggering NewForbidden
return k8s_errors.NewForbidden(
schema.GroupResource{Group: "", Resource: "pods"}, // Specify the group and resource type
pod.Name,
errors.New("Cannot update Pod spec field - Spec.InitContainers[0].Image"), // Specify the error message
)
}

err := controllerutil.SetControllerReference(instance, pod, r.Scheme)
Expand All @@ -603,7 +609,16 @@ func (r *OpenStackClientReconciler) podCreateOrUpdate(
return nil
})
if err != nil {
if common.IsForbiddenPodSpecChangeError(err) || k8s_errors.IsInvalid(err) {
var forbiddenPodSpecChangeErr *k8s_errors.StatusError

forbiddenPodSpec := false
if errors.As(err, &forbiddenPodSpecChangeErr) {
if forbiddenPodSpecChangeErr.ErrStatus.Reason == metav1.StatusReasonForbidden {
forbiddenPodSpec = true
}
}

if forbiddenPodSpec || k8s_errors.IsInvalid(err) {
// Delete pod when an unsupported change was requested, like
// e.g. additional controller VM got up. We just re-create the
// openstackclient pod
Expand Down Expand Up @@ -651,9 +666,7 @@ func (r *OpenStackClientReconciler) podCreateOrUpdate(
return nil
}

//
// NetworkAttachmentDefinition, SriovNetwork and SriovNetworkNodePolicy
//
func (r *OpenStackClientReconciler) verifyNetworkAttachments(
ctx context.Context,
instance *ospdirectorv1beta1.OpenStackClient,
Expand Down Expand Up @@ -711,9 +724,7 @@ func (r *OpenStackClientReconciler) verifyNetworkAttachments(
return ctrl.Result{}, nil
}

//
// PVCs
//
func (r *OpenStackClientReconciler) createPVCs(
ctx context.Context,
instance *ospdirectorv1beta1.OpenStackClient,
Expand Down
8 changes: 0 additions & 8 deletions controllers/openstackconfiggenerator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,7 @@ func (r *OpenStackConfigGeneratorReconciler) verifyNodeResourceStatus(
return msg, true, nil
}

//
// Fencing considerations
//
func (r *OpenStackConfigGeneratorReconciler) createFencingEnvironmentFiles(
ctx context.Context,
instance *ospdirectorv1beta1.OpenStackConfigGenerator,
Expand Down Expand Up @@ -797,9 +795,7 @@ func (r *OpenStackConfigGeneratorReconciler) createFencingEnvironmentFiles(
return renderedFencingTemplate, nil
}

//
// generate TripleoDeploy configmap with environment file containing predictible IPs
//
func (r *OpenStackConfigGeneratorReconciler) createTripleoDeployCM(
ctx context.Context,
instance *ospdirectorv1beta1.OpenStackConfigGenerator,
Expand Down Expand Up @@ -949,9 +945,7 @@ func (r *OpenStackConfigGeneratorReconciler) getClusterServiceEndpoint(
return "", k8s_errors.NewNotFound(appsv1.Resource("service"), fmt.Sprint(labelSelector))
}

//
// Render VM role nic templates, but only for tripleo roles
//
func (r *OpenStackConfigGeneratorReconciler) createVMRoleNicTemplates(
instance *ospdirectorv1beta1.OpenStackConfigGenerator,
ospVersion shared.OSPVersion,
Expand Down Expand Up @@ -1008,10 +1002,8 @@ func (r *OpenStackConfigGeneratorReconciler) createVMRoleNicTemplates(
return roleNicTemplates, nil
}

//
// Verify if ConfigGeneratorInputLabel label is set on the CM which is used to limit
// the CMs to watch
//
func (r *OpenStackConfigGeneratorReconciler) addConfigGeneratorInputLabel(
ctx context.Context,
instance *ospdirectorv1beta1.OpenStackConfigGenerator,
Expand Down
Loading

0 comments on commit 9778447

Please sign in to comment.