@@ -22,15 +22,13 @@ import (
22
22
"github.com/gin-gonic/gin"
23
23
"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
24
24
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25
- "k8s.io/client-go/util/retry"
26
25
"k8s.io/klog/v2"
27
26
"sigs.k8s.io/yaml"
28
27
29
28
"github.com/karmada-io/dashboard/cmd/api/app/router"
30
29
v1 "github.com/karmada-io/dashboard/cmd/api/app/types/api/v1"
31
30
"github.com/karmada-io/dashboard/cmd/api/app/types/common"
32
31
"github.com/karmada-io/dashboard/pkg/client"
33
- "github.com/karmada-io/dashboard/pkg/common/errors"
34
32
"github.com/karmada-io/dashboard/pkg/resource/clusterpropagationpolicy"
35
33
)
36
34
@@ -93,84 +91,6 @@ func handlePostClusterPropagationPolicy(c *gin.Context) {
93
91
common .Success (c , "ok" )
94
92
}
95
93
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
-
174
94
func init () {
175
95
r := router .V1 ()
176
96
r .GET ("/clusterpropagationpolicy" , handleGetClusterPropagationPolicyList )
0 commit comments