2121import io .functionmesh .compute .functions .models .V1alpha1Function ;
2222import io .functionmesh .compute .functions .models .V1alpha1FunctionList ;
2323import io .functionmesh .compute .MeshWorkerService ;
24+ import io .functionmesh .compute .sinks .models .V1alpha1Sink ;
25+ import io .functionmesh .compute .sources .models .V1alpha1Source ;
2426import io .functionmesh .compute .util .KubernetesUtils ;
2527import lombok .extern .slf4j .Slf4j ;
2628import okhttp3 .Call ;
2729import okhttp3 .Response ;
2830import org .apache .commons .codec .digest .DigestUtils ;
31+ import org .apache .commons .lang3 .StringUtils ;
2932import org .apache .pulsar .broker .authentication .AuthenticationDataHttps ;
3033import org .apache .pulsar .broker .authentication .AuthenticationDataSource ;
3134import org .apache .pulsar .client .admin .PulsarAdminException ;
@@ -105,12 +108,22 @@ public void deregisterFunction(final String tenant,
105108 clientAuthenticationDataHttps ,
106109 ComponentTypeUtils .toString (componentType ));
107110 try {
108- Call functionInfoCall =
111+ Call componentCall =
109112 worker ().getCustomObjectsApi ()
110113 .getNamespacedCustomObjectCall (
111114 group , version , KubernetesUtils .getNamespace (worker ().getFactoryConfig ()),
112115 plural , componentName , null );
113- V1alpha1Function v1alpha1Function = executeCall (functionInfoCall , V1alpha1Function .class );
116+ String clusterName ;
117+ if ("Source" .equals (kind )) {
118+ V1alpha1Source v1alpha1Source = executeCall (componentCall , V1alpha1Source .class );
119+ clusterName = v1alpha1Source .getSpec ().getClusterName ();
120+ } else if ("Sink" .equals (kind )) {
121+ V1alpha1Sink v1alpha1Sink = executeCall (componentCall , V1alpha1Sink .class );
122+ clusterName = v1alpha1Sink .getSpec ().getClusterName ();
123+ } else {
124+ V1alpha1Function v1alpha1Function = executeCall (componentCall , V1alpha1Function .class );
125+ clusterName = v1alpha1Function .getSpec ().getClusterName ();
126+ }
114127 Call deleteObjectCall = worker ().getCustomObjectsApi ().deleteNamespacedCustomObjectCall (
115128 group ,
116129 version ,
@@ -126,44 +139,47 @@ public void deregisterFunction(final String tenant,
126139 );
127140 executeCall (deleteObjectCall , null );
128141
129- Call deleteAuthSecretCall = worker ().getCoreV1Api ()
130- .deleteNamespacedSecretCall (
131- KubernetesUtils .getUniqueSecretName (
132- kind .toLowerCase (),
133- "auth" ,
134- DigestUtils .sha256Hex (
135- KubernetesUtils .getSecretName (
136- v1alpha1Function .getSpec ().getClusterName (),
137- tenant , namespace , componentName ))),
138- KubernetesUtils .getNamespace (worker ().getFactoryConfig ()),
139- null ,
140- null ,
141- 30 ,
142- false ,
143- null ,
144- null ,
145- null
146- );
147- executeCall (deleteAuthSecretCall , null );
148- Call deleteTlsSecretCall = worker ().getCoreV1Api ()
149- .deleteNamespacedSecretCall (
150- KubernetesUtils .getUniqueSecretName (
151- kind .toLowerCase (),
152- "tls" ,
153- DigestUtils .sha256Hex (
154- KubernetesUtils .getSecretName (
155- v1alpha1Function .getSpec ().getClusterName (),
156- tenant , namespace , componentName ))),
157- KubernetesUtils .getNamespace (worker ().getFactoryConfig ()),
158- null ,
159- null ,
160- 30 ,
161- false ,
162- null ,
163- null ,
164- null
165- );
166- executeCall (deleteTlsSecretCall , null );
142+ if (!StringUtils .isEmpty (worker ().getWorkerConfig ().getBrokerClientAuthenticationPlugin ())
143+ && !StringUtils .isEmpty (worker ().getWorkerConfig ().getBrokerClientAuthenticationParameters ())) {
144+ Call deleteAuthSecretCall = worker ().getCoreV1Api ()
145+ .deleteNamespacedSecretCall (
146+ KubernetesUtils .getUniqueSecretName (
147+ kind .toLowerCase (),
148+ "auth" ,
149+ DigestUtils .sha256Hex (
150+ KubernetesUtils .getSecretName (
151+ clusterName , tenant , namespace , componentName ))),
152+ KubernetesUtils .getNamespace (worker ().getFactoryConfig ()),
153+ null ,
154+ null ,
155+ 30 ,
156+ false ,
157+ null ,
158+ null ,
159+ null
160+ );
161+ executeCall (deleteAuthSecretCall , null );
162+ }
163+ if (worker ().getWorkerConfig ().getTlsEnabled ()) {
164+ Call deleteTlsSecretCall = worker ().getCoreV1Api ()
165+ .deleteNamespacedSecretCall (
166+ KubernetesUtils .getUniqueSecretName (
167+ kind .toLowerCase (),
168+ "tls" ,
169+ DigestUtils .sha256Hex (
170+ KubernetesUtils .getSecretName (
171+ clusterName , tenant , namespace , componentName ))),
172+ KubernetesUtils .getNamespace (worker ().getFactoryConfig ()),
173+ null ,
174+ null ,
175+ 30 ,
176+ false ,
177+ null ,
178+ null ,
179+ null
180+ );
181+ executeCall (deleteTlsSecretCall , null );
182+ }
167183 } catch (Exception e ) {
168184 log .error ("deregister {}/{}/{} {} failed" , tenant , namespace , componentName , plural , e );
169185 throw new RestException (javax .ws .rs .core .Response .Status .INTERNAL_SERVER_ERROR , e .getMessage ());
0 commit comments