-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rokibul Hasan <[email protected]>
- Loading branch information
1 parent
9a86127
commit 1c5da0c
Showing
15 changed files
with
1,356 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
Copyright AppsCode Inc. and Contributors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package clusterclaim | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/utils/ptr" | ||
cu "kmodules.xyz/client-go/client" | ||
uiapi "kmodules.xyz/resource-metadata/apis/ui/v1alpha1" | ||
clusterv1alpha1 "open-cluster-management.io/api/cluster/v1alpha1" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
const FeatureClusterClaim = "features.appscode.com" | ||
|
||
type ClusterClaimReconciler struct { | ||
kc client.Client | ||
} | ||
|
||
var _ reconcile.Reconciler = &ClusterClaimReconciler{} | ||
|
||
func NewReconciler(kc client.Client) *ClusterClaimReconciler { | ||
return &ClusterClaimReconciler{ | ||
kc: kc, | ||
} | ||
} | ||
|
||
func (r *ClusterClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
var err error | ||
var featureList uiapi.FeatureList | ||
if err = r.kc.List(ctx, &featureList); err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
var enabledFeatures []string | ||
var notManagedFeatures []string | ||
var disabledFeatures []string | ||
|
||
for _, feature := range featureList.Items { | ||
if feature.Status.Enabled == nil { | ||
return ctrl.Result{}, fmt.Errorf("feature is not reconciled yet") | ||
} | ||
if ptr.Deref(feature.Status.Enabled, false) { | ||
enabledFeatures = append(enabledFeatures, feature.Name) | ||
if !ptr.Deref(feature.Status.Managed, false) { | ||
notManagedFeatures = append(notManagedFeatures, feature.Name) | ||
} | ||
} | ||
|
||
if feature.Spec.Disabled { | ||
disabledFeatures = append(disabledFeatures, feature.Name) | ||
} | ||
} | ||
|
||
data, err := yaml.Marshal(map[string]any{ | ||
"enabledFeatures": enabledFeatures, | ||
"notManagedFeatures": notManagedFeatures, | ||
"disabledFeatures": disabledFeatures, | ||
}) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
obj := &clusterv1alpha1.ClusterClaim{ | ||
TypeMeta: metav1.TypeMeta{}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: FeatureClusterClaim, | ||
}, | ||
} | ||
_, err = cu.CreateOrPatch(context.TODO(), r.kc, obj, func(o client.Object, createOp bool) client.Object { | ||
in := o.(*clusterv1alpha1.ClusterClaim) | ||
in.Spec.Value = string(data) | ||
return in | ||
}) | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
// SetupWithManager sets up the controller with the Manager. | ||
func (r *ClusterClaimReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||
return ctrl.NewControllerManagedBy(mgr). | ||
For(&uiapi.Feature{}). | ||
Complete(r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.