Skip to content

Commit

Permalink
comments gardener#1
Browse files Browse the repository at this point in the history
  • Loading branch information
kon-angelo committed May 28, 2024
1 parent 16d5ac2 commit 58baaee
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 50 deletions.
4 changes: 2 additions & 2 deletions hack/api-reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@ ShareNetwork
</td>
<td>
<em>(Optional)</em>
<p>ShareNetwork holds information about the share network (used for shared2 file systems like NFS)</p>
<p>ShareNetwork holds information about the share network (used for shared file systems like NFS)</p>
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -1723,7 +1723,7 @@ string
<a href="#openstack.provider.extensions.gardener.cloud/v1alpha1.Networks">Networks</a>)
</p>
<p>
<p>ShareNetwork holds information about the share network (used for shared2 file systems like NFS)</p>
<p>ShareNetwork holds information about the share network (used for shared file systems like NFS)</p>
</p>
<table>
<thead>
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/openstack/types_infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Networks struct {
Workers string
// ID is the ID of an existing private network.
ID *string
// ShareNetwork holds information about the share network (used for shared2 file systems like NFS)
// ShareNetwork holds information about the share network (used for shared file systems like NFS)
ShareNetwork *ShareNetwork
}

Expand All @@ -43,7 +43,7 @@ type Router struct {
ID string
}

// ShareNetwork holds information about the share network (used for shared2 file systems like NFS)
// ShareNetwork holds information about the share network (used for shared file systems like NFS)
type ShareNetwork struct {
// Enabled is the switch to enable the creation of a share network
Enabled bool
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/openstack/v1alpha1/types_infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Networks struct {
// ID is the ID of an existing private network.
// +optional
ID *string `json:"id,omitempty"`
// ShareNetwork holds information about the share network (used for shared2 file systems like NFS)
// ShareNetwork holds information about the share network (used for shared file systems like NFS)
// +optional
ShareNetwork *ShareNetwork `json:"shareNetwork,omitempty"`
}
Expand All @@ -48,7 +48,7 @@ type Router struct {
ID string `json:"id"`
}

// ShareNetwork holds information about the share network (used for shared2 file systems like NFS)
// ShareNetwork holds information about the share network (used for shared file systems like NFS)
type ShareNetwork struct {
// Enabled is the switch to enable the creation of a share network
Enabled bool `json:"enabled"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/infrastructure/actuator_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/gardener/gardener-extension-provider-openstack/pkg/apis/openstack/helper"
)

// Delete implements infrastructure.Actuator.
// Delete the Infrastructure config.
func (a *actuator) Delete(ctx context.Context, log logr.Logger, infra *extensionsv1alpha1.Infrastructure, cluster *extensionscontroller.Cluster) error {
return util.DetermineError(a.delete(ctx, log, OnDelete, infra, cluster), helper.KnownCodes)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/infrastructure/actuator_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
infrainternal "github.com/gardener/gardener-extension-provider-openstack/pkg/internal/infrastructure"
)

// Migrate implements infrastructure.Actuator.
// Migrate deletes the k8s infrastructure resources without deleting the corresponding resources in the IaaS provider.
func (a *actuator) Migrate(ctx context.Context, log logr.Logger, infra *extensionsv1alpha1.Infrastructure, _ *controller.Cluster) error {
tf, err := internal.NewTerraformer(log, a.restConfig, infrainternal.TerraformerPurpose, infra, a.disableProjectedTokenMount)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/infrastructure/actuator_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/gardener/gardener-extension-provider-openstack/pkg/apis/openstack/helper"
)

// Reconcile implements infrastructure.Actuator.
// Reconcile the Infrastructure config.
func (a *actuator) Reconcile(ctx context.Context, log logr.Logger, infra *extensionsv1alpha1.Infrastructure, cluster *controller.Cluster) error {
return util.DetermineError(a.reconcile(ctx, log, OnReconcile, infra, cluster), helper.KnownCodes)
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/controller/infrastructure/flow_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ type FlowReconciler struct {
}

// NewFlowReconciler creates a new flow reconciler.
func NewFlowReconciler(client client.Client, restConfig *rest.Config, log logr.Logger, projToken bool) (Reconciler, error) {
func NewFlowReconciler(client client.Client, restConfig *rest.Config, log logr.Logger, projToken bool) Reconciler {
return &FlowReconciler{
client: client,
restConfig: restConfig,
log: log,
disableProjectedTokenMount: projToken,
}, nil
}
}

// Reconcile reconciles the infrastructure and returns the status (state of the world), the state (input for the next loops) and any errors that occurred.
// Reconcile reconciles the infrastructure and updates the Infrastructure status (state of the world), the state (input for the next loops) or reports any errors that occurred.
func (f *FlowReconciler) Reconcile(ctx context.Context, infra *extensionsv1alpha1.Infrastructure, cluster *controller.Cluster) error {
var (
infraState *openstack.InfrastructureState
Expand Down Expand Up @@ -164,8 +164,9 @@ func (f *FlowReconciler) migrateFromTerraform(ctx context.Context, infra *extens
Data: map[string]string{},
}
)
// we want to prevent allowing the deletion of infrastructure if there may be still resources in the cloudprovider. We will initialize the data
// with a specific "marker" so that the deletion
// we want to prevent the deletion of Infrastructure CR if there may be still resources in the cloudprovider. We will initialize the data
// with a specific "marker" so that deletion attempts will not skip the deletion if we are certain that terraform had created infra resources
// in past reconciliation.
tf, err := internal.NewTerraformer(f.log, f.restConfig, infrainternal.TerraformerPurpose, infra, f.disableProjectedTokenMount)
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (a *networkingAccess) CreateRouter(desired *Router) (router *Router, err er
// create router in first available subnet
for _, subnetID := range desired.ExternalSubnetIDs {
router, err = a.tryCreateRouter(desired, &subnetID)
// if there is an error, then we keep trying along the available list of subnets for the first successful operation.
// if there is retryable error, then we keep trying along the available list of subnets for the first successful operation.
if err != nil && !retryOnError(a.log, err) {
return
}
Expand Down
7 changes: 2 additions & 5 deletions pkg/controller/infrastructure/infraflow/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const (
NameKeyPair = "KeyPair"
// NameSecGroup is the name of the security group
NameSecGroup = "SecurityGroupName"
// NameShareNetwork is the name of the shared2 network
// NameShareNetwork is the name of the shared network
NameShareNetwork = "ShareNetworkName"

// RouterIP is the key for the router IP address
Expand Down Expand Up @@ -161,10 +161,7 @@ func (fctx *FlowContext) computeInfrastructureState() *runtime.RawExtension {

func (fctx *FlowContext) computeInfrastructureStatus() *openstackv1alpha1.InfrastructureStatus {
status := &openstackv1alpha1.InfrastructureStatus{
TypeMeta: metav1.TypeMeta{
APIVersion: openstackv1alpha1.SchemeGroupVersion.String(),
Kind: "InfrastructureStatus",
},
TypeMeta: infrainternal.StatusTypeMeta,
}

status.Networks.FloatingPool.ID = ptr.Deref(fctx.state.Get(IdentifierFloatingNetwork), "")
Expand Down
6 changes: 1 addition & 5 deletions pkg/controller/infrastructure/strategyselector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package infrastructure
import (
"context"
"encoding/json"
"fmt"
"strconv"

"github.com/gardener/gardener/extensions/pkg/controller"
Expand Down Expand Up @@ -44,10 +43,7 @@ type ReconcilerFactoryImpl struct {
// Build builds the Reconciler according to the arguments.
func (f ReconcilerFactoryImpl) Build(useFlow bool) (Reconciler, error) {
if useFlow {
reconciler, err := NewFlowReconciler(f.a.client, f.a.restConfig, f.log, f.a.disableProjectedTokenMount)
if err != nil {
return nil, fmt.Errorf("failed to init flow reconciler: %w", err)
}
reconciler := NewFlowReconciler(f.a.client, f.a.restConfig, f.log, f.a.disableProjectedTokenMount)
return reconciler, nil
}

Expand Down
21 changes: 9 additions & 12 deletions pkg/controller/infrastructure/terraform_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (t *TerraformReconciler) reconcile(ctx context.Context, infra *extensionsv1

tf, err := internal.NewTerraformerWithAuth(log, t.restConfig, infrastructure.TerraformerPurpose, infra, credentials, t.disableProjectedTokenMount)
if err != nil {
return util.DetermineError(err, helper.KnownCodes)
return err
}

if err := tf.
Expand All @@ -115,7 +115,7 @@ func (t *TerraformReconciler) Delete(ctx context.Context, infra *extensionsv1alp
func (t *TerraformReconciler) delete(ctx context.Context, infra *extensionsv1alpha1.Infrastructure, cluster *extensions.Cluster) error {
tf, err := internal.NewTerraformer(t.log, t.restConfig, infrastructure.TerraformerPurpose, infra, t.disableProjectedTokenMount)
if err != nil {
return util.DetermineError(fmt.Errorf("could not create the Terraformer: %+v", err), helper.KnownCodes)
return fmt.Errorf("could not create the Terraformer: %+v", err)
}

// terraform pod from previous reconciliation might still be running, ensure they are gone before doing any operations
Expand Down Expand Up @@ -144,34 +144,34 @@ func (t *TerraformReconciler) delete(ctx context.Context, infra *extensionsv1alp
// need to know if application credentials are used
credentials, err := openstack.GetCredentials(ctx, t.client, infra.Spec.SecretRef, false)
if err != nil {
return util.DetermineError(err, helper.KnownCodes)
return err
}

openstackClient, err := openstackclient.NewOpenstackClientFromCredentials(credentials)
if err != nil {
return util.DetermineError(err, helper.KnownCodes)
return err
}

networkingClient, err := openstackClient.Networking()
if err != nil {
return util.DetermineError(err, helper.KnownCodes)
return err
}
loadbalancerClient, err := openstackClient.Loadbalancing()
if err != nil {
return util.DetermineError(err, helper.KnownCodes)
return err
}

stateInitializer := terraformer.StateConfigMapInitializerFunc(terraformer.CreateState)
tf = tf.InitializeWith(ctx, terraformer.DefaultInitializer(t.client, terraformFiles.Main, terraformFiles.Variables, terraformFiles.TFVars, stateInitializer)).SetEnvVars(internal.TerraformerEnvVars(infra.Spec.SecretRef, credentials)...)

configExists, err := tf.ConfigExists(ctx)
if err != nil {
return util.DetermineError(err, helper.KnownCodes)
return err
}

vars, err := tf.GetStateOutputVariables(ctx, infrastructure.TerraformOutputKeyRouterID)
if err != nil && !terraformer.IsVariablesNotFoundError(err) {
return util.DetermineError(err, helper.KnownCodes)
return err
}

var (
Expand Down Expand Up @@ -200,10 +200,7 @@ func (t *TerraformReconciler) delete(ctx context.Context, infra *extensionsv1alp
f = g.Compile()
)

if err := f.Run(ctx, flow.Opts{}); err != nil {
return util.DetermineError(flow.Errors(err), helper.KnownCodes)
}
return nil
return f.Run(ctx, flow.Opts{Log: t.log})
}

func (t *TerraformReconciler) computeTerraformStatusState(
Expand Down
9 changes: 0 additions & 9 deletions pkg/internal/infrastructure/infrastucture.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,6 @@ func PatchProviderStatusAndState(
status *openstackv1alpha1.InfrastructureStatus,
state *runtime.RawExtension,
) error {

// infraObjectKey := client.ObjectKey{
// Namespace: infra.Namespace,
// Name: infra.Name,
// }
// if err := runtimeClient.Get(ctx, infraObjectKey, infra); err != nil {
// return err
// }

patch := client.MergeFrom(infra.DeepCopy())
if status != nil {
infra.Status.ProviderStatus = &runtime.RawExtension{Object: status}
Expand Down
5 changes: 1 addition & 4 deletions pkg/internal/infrastructure/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,7 @@ func StatusFromTerraformState(state *TerraformState) *apiv1alpha1.Infrastructure
}
}
return &apiv1alpha1.InfrastructureStatus{
TypeMeta: metav1.TypeMeta{
APIVersion: apiv1alpha1.SchemeGroupVersion.String(),
Kind: "InfrastructureStatus",
},
TypeMeta: StatusTypeMeta,
Networks: apiv1alpha1.NetworkStatus{
ID: state.NetworkID,
Name: state.NetworkName,
Expand Down

0 comments on commit 58baaee

Please sign in to comment.