Remove hardcoded condition type. (#166)
Signed-off-by: RainbowMango <renhongcai@huawei.com>
This commit is contained in:
parent
3305a54b11
commit
c5502fc434
|
@ -12,7 +12,6 @@ func main() {
|
||||||
logs.InitLogs()
|
logs.InitLogs()
|
||||||
defer logs.FlushLogs()
|
defer logs.FlushLogs()
|
||||||
|
|
||||||
// TODO: remove dependency on apiserver
|
|
||||||
stopChan := apiserver.SetupSignalHandler()
|
stopChan := apiserver.SetupSignalHandler()
|
||||||
|
|
||||||
if err := app.NewSchedulerCommand(stopChan).Execute(); err != nil {
|
if err := app.NewSchedulerCommand(stopChan).Execute(); err != nil {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
|
@ -90,8 +90,8 @@ func (c *Controller) syncWork(propagationWork *policyv1alpha1.PropagationWork) (
|
||||||
// isResourceApplied checking weather resource has been dispatched to member cluster or not
|
// isResourceApplied checking weather resource has been dispatched to member cluster or not
|
||||||
func (c *Controller) isResourceApplied(propagationWorkStatus *policyv1alpha1.PropagationWorkStatus) bool {
|
func (c *Controller) isResourceApplied(propagationWorkStatus *policyv1alpha1.PropagationWorkStatus) bool {
|
||||||
for _, condition := range propagationWorkStatus.Conditions {
|
for _, condition := range propagationWorkStatus.Conditions {
|
||||||
if condition.Type == "Applied" {
|
if condition.Type == policyv1alpha1.WorkApplied {
|
||||||
if condition.Status == v1.ConditionTrue {
|
if condition.Status == metav1.ConditionTrue {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ func (c *Controller) syncToClusters(cluster *v1alpha1.Cluster, propagationWork *
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
clusterObj, err := clusterDynamicClient.DynamicClientSet.Resource(dynamicResource).Namespace(workload.GetNamespace()).Get(context.TODO(), workload.GetName(), v1.GetOptions{})
|
clusterObj, err := clusterDynamicClient.DynamicClientSet.Resource(dynamicResource).Namespace(workload.GetNamespace()).Get(context.TODO(), workload.GetName(), metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("Failed to get resource %v from member cluster, err is %v ", workload.GetName(), err)
|
klog.Errorf("Failed to get resource %v from member cluster, err is %v ", workload.GetName(), err)
|
||||||
return err
|
return err
|
||||||
|
@ -235,16 +235,12 @@ func (c *Controller) removeFinalizer(propagationWork *policyv1alpha1.Propagation
|
||||||
|
|
||||||
// updateAppliedCondition update the Applied condition for the given PropagationWork
|
// updateAppliedCondition update the Applied condition for the given PropagationWork
|
||||||
func (c *Controller) updateAppliedCondition(propagationWork *policyv1alpha1.PropagationWork) error {
|
func (c *Controller) updateAppliedCondition(propagationWork *policyv1alpha1.PropagationWork) error {
|
||||||
currentTime := v1.Now()
|
newPropagationWorkAppliedCondition := metav1.Condition{
|
||||||
propagationWorkApplied := "Applied"
|
Type: policyv1alpha1.WorkApplied,
|
||||||
appliedSuccess := "AppliedSuccess"
|
Status: metav1.ConditionTrue,
|
||||||
resourceApplied := "Success sync resource in member cluster"
|
Reason: "AppliedSuccessful",
|
||||||
newPropagationWorkAppliedCondition := v1.Condition{
|
Message: "Manifest has been successfully applied",
|
||||||
Type: propagationWorkApplied,
|
LastTransitionTime: metav1.Now(),
|
||||||
Status: v1.ConditionTrue,
|
|
||||||
Reason: appliedSuccess,
|
|
||||||
Message: resourceApplied,
|
|
||||||
LastTransitionTime: currentTime,
|
|
||||||
}
|
}
|
||||||
propagationWork.Status.Conditions = append(propagationWork.Status.Conditions, newPropagationWorkAppliedCondition)
|
propagationWork.Status.Conditions = append(propagationWork.Status.Conditions, newPropagationWorkAppliedCondition)
|
||||||
err := c.Client.Status().Update(context.TODO(), propagationWork)
|
err := c.Client.Status().Update(context.TODO(), propagationWork)
|
||||||
|
|
|
@ -14,7 +14,6 @@ import (
|
||||||
// IsClusterReady tells whether the cluster status in 'Ready' condition.
|
// IsClusterReady tells whether the cluster status in 'Ready' condition.
|
||||||
func IsClusterReady(clusterStatus *v1alpha1.ClusterStatus) bool {
|
func IsClusterReady(clusterStatus *v1alpha1.ClusterStatus) bool {
|
||||||
for _, condition := range clusterStatus.Conditions {
|
for _, condition := range clusterStatus.Conditions {
|
||||||
// TODO(RainbowMango): Condition type should be defined in API, and after that update this hard code accordingly.
|
|
||||||
if condition.Type == v1alpha1.ClusterConditionReady {
|
if condition.Type == v1alpha1.ClusterConditionReady {
|
||||||
if condition.Status == metav1.ConditionTrue {
|
if condition.Status == metav1.ConditionTrue {
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in New Issue