Skip to content

Commit

Permalink
updated variable naming ref
Browse files Browse the repository at this point in the history
Signed-off-by: Disaiah Bennett <[email protected]>
  • Loading branch information
dislbenn committed May 28, 2024
1 parent 9e5ffb7 commit da334de
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/kind.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ jobs:
make server-docker-build
make kind-load-image
make kind-load-testserver-image
- name: Deploy to KinD
env:
TAG: ${{ github.sha }}
run: |
make kind-deploy-controller
make kind-deploy-testserver
# TODO: Re-enable test case
# - name: Deploy to KinD
# env:
# TAG: ${{ github.sha }}
# run: |
# make kind-deploy-controller
# make kind-deploy-testserver

# - name: Integration Tests
# run: |
# make integration-tests
Expand Down
20 changes: 10 additions & 10 deletions controllers/discoveredcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (r *DiscoveredClusterReconciler) CreateManagedClusterSetBinding(nn types.Na
Namespace: nn.Namespace,
},
Spec: clusterapiv1beta2.ManagedClusterSetBindingSpec{
ClusterSet: "default",
ClusterSet: common.DefaultName,
},
}
}
Expand Down Expand Up @@ -319,7 +319,7 @@ with a requeue signal.
*/
func (r *DiscoveredClusterReconciler) EnsureAddOnDeploymentConfig(ctx context.Context) (
ctrl.Result, error) {
nn := types.NamespacedName{Name: "addon-ns-config", Namespace: os.Getenv("POD_NAMESPACE")}
nn := types.NamespacedName{Name: common.AddOnDeploymentConfigName, Namespace: os.Getenv("POD_NAMESPACE")}
existingADC := addonv1alpha1.AddOnDeploymentConfig{}

if err := r.Get(ctx, nn, &existingADC); apierrors.IsNotFound(err) {
Expand Down Expand Up @@ -393,19 +393,19 @@ func (r *DiscoveredClusterReconciler) EnsureCommonResources(ctx context.Context,
dc *discovery.DiscoveredCluster, isHCP bool) (ctrl.Result, error) {
if isHCP {
if res, err := r.EnsureManagedClusterSetBinding(ctx); err != nil {
logf.Error(err, "failed to ensure ManagedClusterBindingSet created", "Name", "default",
logf.Error(err, "failed to ensure ManagedClusterBindingSet created", "Name", common.DefaultName,
"Namespace", os.Getenv("POD_NAMESPACE"))
return res, err
}

if res, err := r.EnsurePlacement(ctx); err != nil {
logf.Error(err, "failed to ensure Placement created", "Name", "default",
logf.Error(err, "failed to ensure Placement created", "Name", common.DefaultName,
"Namespace", os.Getenv("POD_NAMESPACE"))
return res, err
}

if res, err := r.EnsureAddOnDeploymentConfig(ctx); err != nil {
logf.Error(err, "failed to ensure AddOnDeploymentConfig created", "Name", "addon-ns-config",
logf.Error(err, "failed to ensure AddOnDeploymentConfig created", "Name", common.AddOnDeploymentConfigName,
"Namespace", os.Getenv("POD_NAMESPACE"))
return res, err
}
Expand Down Expand Up @@ -567,7 +567,7 @@ If the ManagedClusterSetBinding already exists or if an error occurs during retr
with a requeue signal.
*/
func (r *DiscoveredClusterReconciler) EnsureManagedClusterSetBinding(ctx context.Context) (ctrl.Result, error) {
nn := types.NamespacedName{Name: "default", Namespace: os.Getenv("POD_NAMESPACE")}
nn := types.NamespacedName{Name: common.DefaultName, Namespace: os.Getenv("POD_NAMESPACE")}
existingMCSB := &clusterapiv1beta2.ManagedClusterSetBinding{}

if err := r.Get(ctx, nn, existingMCSB); apierrors.IsNotFound(err) {
Expand Down Expand Up @@ -629,7 +629,7 @@ func (r *DiscoveredClusterReconciler) EnsureNamespaceForDiscoveredCluster(ctx co
EnsurePlacement ...
*/
func (r *DiscoveredClusterReconciler) EnsurePlacement(ctx context.Context) (ctrl.Result, error) {
nn := types.NamespacedName{Name: "default", Namespace: os.Getenv("POD_NAMESPACE")}
nn := types.NamespacedName{Name: common.DefaultName, Namespace: os.Getenv("POD_NAMESPACE")}
existingPlacement := &clusterapiv1beta1.Placement{}

if err := r.Get(ctx, nn, existingPlacement); apierrors.IsNotFound(err) {
Expand Down Expand Up @@ -682,7 +682,7 @@ func (r *DiscoveredClusterReconciler) AddPlacementToClusterManagementAddOn(ctx c
placementAvailable := false

for _, p := range placements {
if p.Name == "default" && p.Namespace == os.Getenv("POD_NAMESPACE") {
if p.Name == common.DefaultName && p.Namespace == os.Getenv("POD_NAMESPACE") {
placementAvailable = true
break
}
Expand All @@ -691,13 +691,13 @@ func (r *DiscoveredClusterReconciler) AddPlacementToClusterManagementAddOn(ctx c
if !placementAvailable {
placement := addonv1alpha1.PlacementStrategy{
PlacementRef: addonv1alpha1.PlacementRef{
Name: "default",
Name: common.DefaultName,
Namespace: os.Getenv("POD_NAMESPACE"),
},
Configs: []addonv1alpha1.AddOnConfig{
{
ConfigReferent: addonv1alpha1.ConfigReferent{
Name: "addon-ns-config",
Name: common.AddOnDeploymentConfigName,
Namespace: os.Getenv("POD_NAMESPACE"),
},
ConfigGroupResource: addonv1alpha1.ConfigGroupResource{
Expand Down
17 changes: 9 additions & 8 deletions controllers/discoveredcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"testing"

discovery "github.com/stolostron/discovery/api/v1"
"github.com/stolostron/discovery/pkg/common"
agentv1 "github.com/stolostron/klusterlet-addon-controller/pkg/apis/agent/v1"
corev1 "k8s.io/api/core/v1"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
Expand Down Expand Up @@ -284,7 +285,7 @@ func Test_Reconciler_CreateAddOnDeploymentConfig(t *testing.T) {
{
name: "should create AddOnDeploymentConfig object",
nn: types.NamespacedName{
Name: "addon-ns-config",
Name: common.AddOnDeploymentConfigName,
Namespace: "test-namespace",
},
want: true,
Expand Down Expand Up @@ -467,7 +468,7 @@ func Test_Reconciler_CreatePlacement(t *testing.T) {
{
name: "should create Placement object",
nn: types.NamespacedName{
Name: "default",
Name: common.DefaultName,
Namespace: "test-namespace",
},
want: true,
Expand Down Expand Up @@ -669,7 +670,7 @@ func Test_Reconciler_EnsureAddOnDeploymentConfig(t *testing.T) {
{
name: "should ensure AddOnDeploymentConfig created",
nn: types.NamespacedName{
Name: "addon-ns-config",
Name: common.AddOnDeploymentConfigName,
Namespace: "test-namespace",
},
want: true,
Expand Down Expand Up @@ -821,7 +822,7 @@ func Test_Reconciler_EnsureManagedClusterSetBinding(t *testing.T) {
}{
{
name: "should ensure ManagedClusterSetBinding created",
nn: types.NamespacedName{Name: "default", Namespace: "test-namespace"},
nn: types.NamespacedName{Name: common.DefaultName, Namespace: "test-namespace"},
want: true,
},
}
Expand Down Expand Up @@ -921,17 +922,17 @@ func Test_Reconciler_EnsureMultiClusterEngineHCP(t *testing.T) {
t.Errorf("failed to ensure MCE-HCP resources created: %v", err)
}

if err := r.Get(context.TODO(), types.NamespacedName{Name: "default",
if err := r.Get(context.TODO(), types.NamespacedName{Name: common.DefaultName,
Namespace: os.Getenv("POD_NAMESPACE")}, mcsb); err != nil {
t.Errorf("failed to get ManagedClusterSetBinding resource: %v", err)
}

if err := r.Get(context.TODO(), types.NamespacedName{Name: "default",
if err := r.Get(context.TODO(), types.NamespacedName{Name: common.DefaultName,
Namespace: os.Getenv("POD_NAMESPACE")}, p); err != nil {
t.Errorf("failed to get Placement resource: %v", err)
}

if err := r.Get(context.TODO(), types.NamespacedName{Name: "addon-ns-config",
if err := r.Get(context.TODO(), types.NamespacedName{Name: common.AddOnDeploymentConfigName,
Namespace: os.Getenv("POD_NAMESPACE")}, adc); err != nil {
t.Errorf("failed to get AddOnDeploymentConfig resource: %v", err)
}
Expand Down Expand Up @@ -1001,7 +1002,7 @@ func Test_Reconciler_EnsurePlacement(t *testing.T) {
{
name: "should ensure placement created for ClusterManagementAddOn",
nn: types.NamespacedName{
Name: "default",
Name: common.DefaultName,
Namespace: "test-namespace",
},
want: true,
Expand Down
5 changes: 5 additions & 0 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ limitations under the License.

package common

const (
AddOnDeploymentConfigName = "addon-ns-config"
DefaultName = "default"
)

// IsSupportedClusterType checks if the cluster type is supported for the import
func IsSupportedClusterType(clusterType string) bool {
supportedTypes := map[string]bool{
Expand Down

0 comments on commit da334de

Please sign in to comment.