Skip to content

Commit

Permalink
enhance clusterdeployment tests
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Bortnikov <[email protected]>
  • Loading branch information
BROngineer committed Dec 28, 2024
1 parent 8010dd2 commit fe7bc24
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 90 deletions.
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ CAPI_OPERATOR_VERSION ?= v$(shell $(YQ) -r '.dependencies.[] | select(.name == "
CAPI_OPERATOR_CRD_PREFIX ?= "operator.cluster.x-k8s.io_"
CAPI_OPERATOR_CRDS ?= capi-operator-crds

CLUSTER_API_VERSION ?= v1.9.3
CLUSTER_API_CRD_PREFIX ?= "cluster.x-k8s.io_"
CLUSTER_API_CRDS ?= cluster-api-crds

## Tool Binaries
KUBECTL ?= kubectl
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
Expand Down Expand Up @@ -511,8 +515,15 @@ $(CAPI_OPERATOR_CRDS): | $(YQ) $(EXTERNAL_CRD_DIR)
curl -s --fail https://raw.githubusercontent.com/kubernetes-sigs/cluster-api-operator/$(CAPI_OPERATOR_VERSION)/config/crd/bases/$(CAPI_OPERATOR_CRD_PREFIX)${name}.yaml \
> $(EXTERNAL_CRD_DIR)/$(CAPI_OPERATOR_CRD_PREFIX)${name}-$(CAPI_OPERATOR_VERSION).yaml;)

$(CLUSTER_API_CRDS): | $(YQ) $(EXTERNAL_CRD_DIR)
rm -f $(EXTERNAL_CRD_DIR)/$(CLUSTER_API_CRD_PREFIX)*
@$(foreach name, \
clusters machinedeployments, \
curl -s --fail https://raw.githubusercontent.com/kubernetes-sigs/cluster-api/$(CLUSTER_API_VERSION)/config/crd/bases/$(CLUSTER_API_CRD_PREFIX)${name}.yaml \
> $(EXTERNAL_CRD_DIR)/$(CLUSTER_API_CRD_PREFIX)${name}-$(CLUSTER_API_VERSION).yaml;)

.PHONY: external-crd
external-crd: $(FLUX_HELM_CRD) $(FLUX_SOURCE_CHART_CRD) $(FLUX_SOURCE_REPO_CRD) $(SVELTOS_CRD) $(CAPI_OPERATOR_CRDS)
external-crd: $(FLUX_HELM_CRD) $(FLUX_SOURCE_CHART_CRD) $(FLUX_SOURCE_REPO_CRD) $(SVELTOS_CRD) $(CAPI_OPERATOR_CRDS) $(CLUSTER_API_CRDS)

.PHONY: kind
kind: $(KIND) ## Download kind locally if necessary.
Expand Down
8 changes: 4 additions & 4 deletions internal/controller/clusterdeployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const (
DefaultRequeueInterval = 10 * time.Second
)

type HelmActor interface {
type helmActor interface {
DownloadChartFromArtifact(ctx context.Context, artifact *sourcev1.Artifact) (*chart.Chart, error)
InitializeConfiguration(clusterDeployment *hmc.ClusterDeployment, log action.DebugLog) (*action.Configuration, error)
EnsureReleaseWithValues(ctx context.Context, actionConfig *action.Configuration, hcChart *chart.Chart, clusterDeployment *hmc.ClusterDeployment) error
Expand All @@ -68,7 +68,7 @@ type HelmActor interface {
// ClusterDeploymentReconciler reconciles a ClusterDeployment object
type ClusterDeploymentReconciler struct {
client.Client
HelmActor
helmActor
Config *rest.Config
DynamicClient *dynamic.DynamicClient
SystemNamespace string
Expand Down Expand Up @@ -134,7 +134,7 @@ func (r *ClusterDeploymentReconciler) setStatusFromChildObjects(ctx context.Cont

if metaCondition.Reason == "" && metaCondition.Status == metav1.ConditionTrue {
metaCondition.Message += " is Ready"
metaCondition.Reason = "Succeeded"
metaCondition.Reason = hmc.SucceededReason
}
apimeta.SetStatusCondition(clusterDeployment.GetConditions(), metaCondition)
}
Expand Down Expand Up @@ -837,7 +837,7 @@ func (r *ClusterDeploymentReconciler) setAvailableUpgrades(ctx context.Context,

// SetupWithManager sets up the controller with the Manager.
func (r *ClusterDeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error {
r.HelmActor = helm.NewActor(r.Config, r.RESTMapper())
r.helmActor = helm.NewActor(r.Config, r.RESTMapper())

return ctrl.NewControllerManagedBy(mgr).
For(&hmc.ClusterDeployment{}).
Expand Down
Loading

0 comments on commit fe7bc24

Please sign in to comment.