Skip to content

Commit

Permalink
change use flow condition
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-lacoo committed Nov 27, 2023
1 parent 1b68a0c commit 1d80ce7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 29 deletions.
39 changes: 32 additions & 7 deletions pkg/controller/infrastructure/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,17 +526,41 @@ func (a *actuator) makeImageVisibleForShoot(ctx context.Context, log logr.Logger

// Reconcile implements infrastructure.Actuator.
func (a *actuator) Reconcile(ctx context.Context, log logr.Logger, infra *extensionsv1alpha1.Infrastructure, cluster *extensioncontroller.Cluster) error {
if a.shouldUseFlow(infra, cluster) {
err := a.reconcileWithFlow(ctx, log, infra, cluster)
flowState, err := a.getFlowStateFromInfraStatus(infra)
if err != nil {
return util.DetermineError(err, helper.KnownCodes)
}
if flowState == nil {
if a.shouldUseFlow(infra, cluster) {
flowState, err = a.migrateFlowStateFromTerraformerState(ctx, log, infra)
if err != nil {
return util.DetermineError(err, helper.KnownCodes)
}
}
}
if flowState != nil {
err = a.reconcileWithFlow(ctx, log, infra, cluster, flowState)
return util.DetermineError(err, helper.KnownCodes)
}
return a.reconcile(ctx, log, infra, cluster, terraformer.StateConfigMapInitializerFunc(terraformer.CreateState))
}

// Restore implements infrastructure.Actuator.
func (a *actuator) Restore(ctx context.Context, log logr.Logger, infra *extensionsv1alpha1.Infrastructure, cluster *extensioncontroller.Cluster) error {
if a.shouldUseFlow(infra, cluster) {
err := a.reconcileWithFlow(ctx, log, infra, cluster)
flowState, err := a.getFlowStateFromInfraStatus(infra)
if err != nil {
return util.DetermineError(err, helper.KnownCodes)
}
if flowState == nil {
if a.shouldUseFlow(infra, cluster) {
flowState, err = a.migrateFlowStateFromTerraformerState(ctx, log, infra)
if err != nil {
return util.DetermineError(err, helper.KnownCodes)
}
}
}
if flowState != nil {
err = a.reconcileWithFlow(ctx, log, infra, cluster, flowState)
return util.DetermineError(err, helper.KnownCodes)
}
terraformState, err := terraformer.UnmarshalRawState(infra.Status.State)
Expand Down Expand Up @@ -654,10 +678,11 @@ func (a *actuator) cleanupServiceLoadBalancers(ctx context.Context, infra *exten
func (a *actuator) Delete(ctx context.Context, log logr.Logger, infra *extensionsv1alpha1.Infrastructure, _ *extensioncontroller.Cluster) error {
flowState, err := a.getFlowStateFromInfraStatus(infra)
if err != nil {
return err
return util.DetermineError(err, helper.KnownCodes)
}
if flowState != nil {
return a.deleteWithFlow(ctx, log, infra, flowState)
err = a.deleteWithFlow(ctx, log, infra, flowState)
return util.DetermineError(err, helper.KnownCodes)
}

return a.delete(ctx, log, infra)
Expand Down Expand Up @@ -727,7 +752,7 @@ func (a *actuator) ForceDelete(_ context.Context, _ logr.Logger, _ *extensionsv1
func (a *actuator) Migrate(ctx context.Context, log logr.Logger, infra *extensionsv1alpha1.Infrastructure, _ *extensioncontroller.Cluster) error {
flowState, err := a.getFlowStateFromInfraStatus(infra)
if err != nil {
return err
return util.DetermineError(err, helper.KnownCodes)
}
if flowState != nil {
return nil // nothing to do if already using new flow without Terraformer
Expand Down
25 changes: 3 additions & 22 deletions pkg/controller/infrastructure/actuator_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ import (
"strings"

extensioncontroller "github.com/gardener/gardener/extensions/pkg/controller"
"github.com/gardener/gardener/extensions/pkg/util"
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

aliapi "github.com/gardener/gardener-extension-provider-alicloud/pkg/apis/alicloud"
"github.com/gardener/gardener-extension-provider-alicloud/pkg/apis/alicloud/helper"
aliv1alpha1 "github.com/gardener/gardener-extension-provider-alicloud/pkg/apis/alicloud/v1alpha1"
"github.com/gardener/gardener-extension-provider-alicloud/pkg/controller/common"
"github.com/gardener/gardener-extension-provider-alicloud/pkg/controller/infrastructure/infraflow"
Expand All @@ -39,17 +37,12 @@ import (
// - annotation `alicloud.provider.extensions.gardener.cloud/use-flow=true` on shoot resource
// - label `alicloud.provider.extensions.gardener.cloud/use-flow=true` on seed resource (label instead of annotation, as only labels are transported from managedseed to seed object)
func (a *actuator) shouldUseFlow(infrastructure *extensionsv1alpha1.Infrastructure, cluster *extensioncontroller.Cluster) bool {
flowState, err := a.getFlowStateFromInfraStatus(infrastructure)
if err == nil && flowState != nil {
return true
}

return strings.EqualFold(infrastructure.Annotations[aliapi.AnnotationKeyUseFlow], "true") ||
(cluster.Shoot != nil && strings.EqualFold(cluster.Shoot.Annotations[aliapi.AnnotationKeyUseFlow], "true")) ||
(cluster.Seed != nil && strings.EqualFold(cluster.Seed.Labels[aliapi.SeedLabelKeyUseFlow], "true"))
}

func (a *actuator) reconcileWithFlow(ctx context.Context, log logr.Logger, infrastructure *extensionsv1alpha1.Infrastructure, cluster *extensioncontroller.Cluster) error {
func (a *actuator) reconcileWithFlow(ctx context.Context, log logr.Logger, infrastructure *extensionsv1alpha1.Infrastructure, cluster *extensioncontroller.Cluster, oldState *infraflow.PersistentState) error {
log.Info("reconcileWithFlow")

var (
Expand Down Expand Up @@ -77,25 +70,13 @@ func (a *actuator) reconcileWithFlow(ctx context.Context, log logr.Logger, infra
}
}

oldState, err := a.getFlowStateFromInfraStatus(infrastructure)
if err != nil {
return err
}
if oldState == nil {

oldState, err = a.migrateFlowStateFromTerraformerState(ctx, log, infrastructure)
if err != nil {
return err
}
}

flowContext, err := a.createFlowContext(ctx, log, infrastructure, cluster, oldState)
if err != nil {
return err
}
if err = flowContext.Reconcile(ctx); err != nil {
_ = a.updateStatusProvider(ctx, infrastructure, machineImages, flowContext.ExportState())
return util.DetermineError(err, helper.KnownCodes)
return err
}
return a.updateStatusProvider(ctx, infrastructure, machineImages, flowContext.ExportState())
}
Expand Down Expand Up @@ -299,7 +280,7 @@ func (a *actuator) deleteWithFlow(ctx context.Context, log logr.Logger, infrastr
}
if err = flowContext.Delete(ctx); err != nil {
_ = flowContext.PersistState(ctx, true)
return util.DetermineError(err, helper.KnownCodes)
return err
}
return flowContext.PersistState(ctx, true)

Expand Down
19 changes: 19 additions & 0 deletions test/simple/infrastructure/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ import (
alicloudinstall "github.com/gardener/gardener-extension-provider-alicloud/pkg/apis/alicloud/install"
alicloudv1alpha1 "github.com/gardener/gardener-extension-provider-alicloud/pkg/apis/alicloud/v1alpha1"
"github.com/gardener/gardener-extension-provider-alicloud/pkg/controller/infrastructure"

v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"
schedulingv1 "k8s.io/api/scheduling/v1"
)

const (
Expand Down Expand Up @@ -145,6 +148,22 @@ func main() {
flag.Parse()
validateFlags()

priorityClass := &schedulingv1.PriorityClass{
ObjectMeta: metav1.ObjectMeta{
Name: v1beta1constants.PriorityClassNameShootControlPlane300,
},
Description: "PriorityClass for Shoot control plane components",
GlobalDefault: false,
Value: 999998300,
}

if err := c.Create(ctx, priorityClass); err != nil {
if !apiErrors.IsAlreadyExists(err) {
runtimelog.Log.Error(err, "error when create priorityClass")
panic("create priorityClass failed")
}
}

namespace = &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: space_name,
Expand Down

0 comments on commit 1d80ce7

Please sign in to comment.