3
3
import io .fabric8 .kubernetes .api .model .Secret ;
4
4
import io .fabric8 .kubernetes .api .model .SecretBuilder ;
5
5
import io .fabric8 .kubernetes .client .KubernetesClient ;
6
+ import io .fabric8 .kubernetes .client .KubernetesClientException ;
6
7
import io .so1s .backend .domain .auth .repository .UserRepository ;
7
8
import io .so1s .backend .domain .auth .service .UserService ;
8
9
import io .so1s .backend .domain .auth .vo .UserRole ;
9
10
import io .so1s .backend .global .utils .Base64Mapper ;
10
11
import java .util .Optional ;
11
12
import javax .annotation .PostConstruct ;
12
13
import lombok .RequiredArgsConstructor ;
14
+ import org .springframework .context .annotation .Profile ;
13
15
import org .springframework .security .crypto .keygen .KeyGenerators ;
14
16
import org .springframework .security .crypto .password .PasswordEncoder ;
15
17
import org .springframework .stereotype .Component ;
16
18
19
+ @ Profile ("!test" )
17
20
@ Component
18
21
@ RequiredArgsConstructor
19
22
public class AdminInitializer {
@@ -36,8 +39,14 @@ private void saveAdmin(String username, String password) {
36
39
37
40
@ PostConstruct
38
41
private void initAdmin () {
39
- var adminSecret = Optional .ofNullable (
40
- kubernetesClient .secrets ().inNamespace (namespace ).withName (secretName ).get ());
42
+ Optional <Secret > adminSecret = Optional .empty ();
43
+
44
+ try {
45
+ adminSecret = Optional .ofNullable (
46
+ kubernetesClient .secrets ().inNamespace (namespace ).withName (secretName ).get ());
47
+ } catch (KubernetesClientException ignored ) {
48
+
49
+ }
41
50
42
51
adminSecret .ifPresentOrElse ((secret ) -> {
43
52
var data = secret .getData ();
0 commit comments