@@ -22,15 +22,13 @@ import (
2222 "github.com/gin-gonic/gin"
2323 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
2424 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25- "k8s.io/client-go/util/retry"
2625 "k8s.io/klog/v2"
2726 "sigs.k8s.io/yaml"
2827
2928 "github.com/karmada-io/dashboard/cmd/api/app/router"
3029 v1 "github.com/karmada-io/dashboard/cmd/api/app/types/api/v1"
3130 "github.com/karmada-io/dashboard/cmd/api/app/types/common"
3231 "github.com/karmada-io/dashboard/pkg/client"
33- "github.com/karmada-io/dashboard/pkg/common/errors"
3432 "github.com/karmada-io/dashboard/pkg/resource/clusterpropagationpolicy"
3533)
3634
@@ -93,84 +91,6 @@ func handlePostClusterPropagationPolicy(c *gin.Context) {
9391 common .Success (c , "ok" )
9492}
9593
96- func handlePutClusterPropagationPolicy (c * gin.Context ) {
97- ctx := context .Context (c )
98- propagationpolicyRequest := new (v1.PutPropagationPolicyRequest )
99- if err := c .ShouldBind (& propagationpolicyRequest ); err != nil {
100- common .Fail (c , err )
101- return
102- }
103- var err error
104- karmadaClient := client .InClusterKarmadaClient ()
105- // todo check pp exist
106- if propagationpolicyRequest .IsClusterScope {
107- clusterPropagationPolicy := v1alpha1.ClusterPropagationPolicy {}
108- if err = yaml .Unmarshal ([]byte (propagationpolicyRequest .PropagationData ), & clusterPropagationPolicy ); err != nil {
109- klog .ErrorS (err , "Failed to unmarshal ClusterPropagationPolicy" )
110- common .Fail (c , err )
111- return
112- }
113- _ , err = karmadaClient .PolicyV1alpha1 ().ClusterPropagationPolicies ().Update (ctx , & clusterPropagationPolicy , metav1.UpdateOptions {})
114- } else {
115- propagationPolicy := v1alpha1.PropagationPolicy {}
116- if err = yaml .Unmarshal ([]byte (propagationpolicyRequest .PropagationData ), & propagationPolicy ); err != nil {
117- klog .ErrorS (err , "Failed to unmarshal PropagationPolicy" )
118- common .Fail (c , err )
119- return
120- }
121- var oldPropagationPolicy * v1alpha1.PropagationPolicy
122- oldPropagationPolicy , err = karmadaClient .PolicyV1alpha1 ().PropagationPolicies (propagationpolicyRequest .Namespace ).Get (ctx , propagationpolicyRequest .Name , metav1.GetOptions {})
123- if err == nil {
124- // only spec can be updated
125- propagationPolicy .TypeMeta = oldPropagationPolicy .TypeMeta
126- propagationPolicy .ObjectMeta = oldPropagationPolicy .ObjectMeta
127- _ , err = karmadaClient .PolicyV1alpha1 ().PropagationPolicies (propagationpolicyRequest .Namespace ).Update (ctx , & propagationPolicy , metav1.UpdateOptions {})
128- }
129- }
130- if err != nil {
131- klog .ErrorS (err , "Failed to update PropagationPolicy" )
132- common .Fail (c , err )
133- return
134- }
135- common .Success (c , "ok" )
136- }
137- func handleDeleteClusterPropagationPolicy (c * gin.Context ) {
138- ctx := context .Context (c )
139- propagationpolicyRequest := new (v1.DeletePropagationPolicyRequest )
140- if err := c .ShouldBind (& propagationpolicyRequest ); err != nil {
141- common .Fail (c , err )
142- return
143- }
144- var err error
145- karmadaClient := client .InClusterKarmadaClient ()
146- if propagationpolicyRequest .IsClusterScope {
147- err = karmadaClient .PolicyV1alpha1 ().ClusterPropagationPolicies ().Delete (ctx , propagationpolicyRequest .Name , metav1.DeleteOptions {})
148- if err != nil {
149- klog .ErrorS (err , "Failed to delete PropagationPolicy" )
150- common .Fail (c , err )
151- return
152- }
153- } else {
154- err = karmadaClient .PolicyV1alpha1 ().PropagationPolicies (propagationpolicyRequest .Namespace ).Delete (ctx , propagationpolicyRequest .Name , metav1.DeleteOptions {})
155- if err != nil {
156- klog .ErrorS (err , "Failed to delete PropagationPolicy" )
157- common .Fail (c , err )
158- return
159- }
160- _ = retry .OnError (
161- retry .DefaultRetry ,
162- func (err error ) bool {
163- return errors .IsNotFound (err )
164- },
165- func () error {
166- _ , getErr := karmadaClient .PolicyV1alpha1 ().PropagationPolicies (propagationpolicyRequest .Namespace ).Get (ctx , propagationpolicyRequest .Name , metav1.GetOptions {})
167- return getErr
168- })
169- }
170-
171- common .Success (c , "ok" )
172- }
173-
17494func init () {
17595 r := router .V1 ()
17696 r .GET ("/clusterpropagationpolicy" , handleGetClusterPropagationPolicyList )
0 commit comments