2020/06 13

jenkins in kubernetes RBAC, configure master, slave node

랜쳐 쿠버네티스에서 젠킨스 앱을 만들어서 젠킨스를 쓰고있다. 최근에 어떠한 이유로 젠킨스를 처음부터 새로 세팅해야 했다. 일반적인 메모리 설정이라던지.. 계정 설정이라던지 등의 일반적인 설정 말고 쿠버네티스와 관련된 설정을 적는다. 1. RBAC. 젠킨스에서 쿠버네티스의 자원에 접근이 필요할 경우 권한이 필요하다.(젠킨스가 쿠버네티스 안에서 설치된거지만 권한 필요.)예로 젠킨스 안에서 kubectl을 설치한 후에 kubectl을 사용해서 자원(pod이라던가.)을 가져오거나 service의 scale을 컨트롤 하는 코드가 있는 경우에 해당한다. 권한이 없는 경우 이런식으로 에러메시지가 뜬다. ----------------------------------------------------------------..

data engineering 2020.06.29

leetcode 733(bfs), 695(bfs), 407 trapping rain water2(힙,구현,bfs), 945(구현)

733 https://leetcode.com/problems/flood-fill/ bfs문제이다. from collections import deque class Solution(object): def floodFill(self, image, sr, sc, newColor): original_color = image[sr][sc] q = deque([[sr, sc]]) visited = set() while q: x,y = q.popleft() image[x][y] = newColor for _x, _y in [[-1, 0], [0, -1], [0, 1], [1, 0]]: next_x, next_y = x + _x, y + _y if (next_x, next_y) not in visited and 0

leetcode 45(dp), 125(regex), 680(팰린드롬, 구현), 403(dfs)

45 https://leetcode.com/problems/jump-game-ii/ 설명은 코드에 적는다. dp문제이다. class Solution: def jump(self, nums: List[int]) -> int: dp = [99999999]*len(nums) dp[0] = 0 # 인덱스 0에서 시작함. cur_max = 0 for i in range(len(nums)): if i+nums[i] > cur_max: # 현재 갈수 있는 최대거리 이상으로 갈수있을때만 루프를 돈다. cur_max = i+nums[i] # 현재 갈수 있는 최대거리 갱신 for j in range(i+1, min(i+1+nums[i], len(nums))): # 현 위치에서 갈수있는곳들의 값을 업데이트시켜줌. dp[j] ..

leetcode 134(그리디), 543(트리), 228(구현), 55(구현), 1306(dfs)

134 https://leetcode.com/problems/gas-station/ 일단 포인트를 잡으면 이동은 무조건 i에서 i+1로 가고 cost[i]만큼 든다. 충전할수 있는 gas보다 드는 비용인 cost가 더 많으면 돌아올수 없으므로 종료를 시켜주고 시작한다. 마을을 순회하면서 충전되는 양보다 드는 비용이 더 많을 경우 0 ~ 현재위치까지는 시작해봐야 -가 되어서 못 간다는 의미이니 시작점을 다음으로 초기화시켜준다. class Solution(object): def canCompleteCircuit(self, gas, cost): if sum(gas) < sum(cost): return -1 start, gas_left = 0, 0 for i in xrange(len(gas)): gas_left..

leetcode 442(find duplicate), 529(bfs), 107(트리), 637, 429, 111, 993, 50(pow)

442 https://leetcode.com/problems/find-all-duplicates-in-an-array/ 이전에 https://qkqhxla1.tistory.com/1044 요글의 leetcode 287번에서 중복되는 숫자 1개를 찾는 문제를 링크드 리스트에 사이클이 있다고 생각하여 사이클의 시작점을 찾는거로 풀수 있었는데, 같은 조건의 중복되는 숫자가 2개 이상일 경우에는 cycle sort라는게 있다. class Solution: def findDuplicates(self, nums: List[int]) -> List[int]: self.cyclicSort(nums) output = [] for i in range(len(nums)): if nums[i] != i+1: output.ap..

LVM (logical volume manager) 기본 세팅..(aws ec2)

https://youngmind.tistory.com/entry/CentOS-%EA%B0%95%EC%A2%8C-PART-1-8-%EC%8A%A4%ED%86%A0%EB%A6%AC%EC%A7%80-%EA%B4%80%EB%A6%AC-%E3%85%A3%E3%85%8D 의 사진을 가져옴.(문제있을시 글 비공개로 돌리겠습니다!) 일단 LVM에 관해 적는이유는 aws ec2에 새로 몽고디비를 설치하려고 하는데 환경에 문제가 있어서, aws에서 도커로 몽고를 띄울수가 없다. 그래서 온프레미스같이, idc에 설치하듯이 서버에 직접 설치를 해야하는데, 이 경우 완전 새로 만들어진 ec2는 말 그대로 우분투에 디스크를 새로 꼽은 상태이다. 그래서 이 디스크들을 어쩌구저쩌구 가공해주고 마운트해줘야 우리가 쓸수 있는 환경이 나..

data engineering 2020.06.18

recursive file name, content search, pushd, popd

1. '파일명'을 찾을때 find명령어를 많이 쓴다. find를 사용하면 경로를 입력한 파일 내에서 폴더가 있으면 재귀적으로 들어가면서 파일명들을 조건에 맞게 검색이 가능하다. ex) 모든 경로에서 na가 들어간 모든 파일 이름을 찾자 -> find / -name *na* 2>/dev/null 그러면 파일에 쓰여있는 내용들을 현재 파일 내에서 재귀적으로 들어가면서 검색을 하려면 어떻게 해야 할까??grep을 사용하면 현 경로에서 recursive하게 파일 내용들을 검색해볼수 있다. 맥 기준.https://apple.stackexchange.com/questions/275373/how-to-make-grep-work-like-in-ubuntu/275379 를 참조한다. grep -R '검색할 내용' 검색할..

leetcode 647(팰린드롬), 516(팰린드롬), 1143(팰린드롬, lcs), 583

647 https://leetcode.com/problems/palindromic-substrings/ 이전에 https://qkqhxla1.tistory.com/1059 에서 leetcode 5번 문제에 대한 풀이를 적었었는데 같은 문제다. class Solution: def countSubstrings(self, s: str) -> int: ret = 0 for i in range(len(s)): l,r = i, i while 0 int: dp = [[0]*(len(word2)+1) for i in range(len(word1)+1)] for i in range(len(word1)): for j in range(len(word2)): if word1[i] == word2[j]: dp[i+1][j+1]..

leetcode 24(구현, linked_list), 572(트리), 508(트리)

24 https://leetcode.com/problems/swap-nodes-in-pairs/ 가져와서 구현해준다. https://leetcode.com/problems/swap-nodes-in-pairs/discuss/œ/Python-or-Dummynode에 좋은 풀이가 있다. 내 답은 드러워서 안적음 class Solution: def swapPairs(self, head: Optional[ListNode]) -> Optional[ListNode]: dummy = p = ListNode(0) dummy.next = head while head and head.next: tmp = head.next head.next = tmp.next tmp.next = head p.next = tmp head = ..

leetcode 208(trie, 트라이), 648(trie), 676(trie)

208 https://leetcode.com/problems/implement-trie-prefix-tree/ https://qkqhxla1.tistory.com/1081?category=685988 에서 만든 코드를 갖다 쓴다. class Trie(object): def __init__(self): self.trie={} def insert(self, word): trie=self.trie for c in word: if c not in trie: trie[c]={} trie=trie[c] trie['#']='#' def search(self, word): stack = deque([[word, self.trie]]) while stack: word, trie = stack.pop() if not wo..

트라이(trie) 파이썬

https://qkqhxla1.tistory.com/700 그림을 다시 가져옴.아주 예전에 정리했었는데 c++이고.. 좀 복잡해서 지나면 잊어버린다. 파이썬 딕셔너리로 쉽게 구현한 버전이 있어서 가져왔다. MyPrettyPrinter클래스는 디버깅용이니 무시하고 Trie클래스만 보자. 소스 출처 : https://leetcode.com/problems/add-and-search-word-data-structure-design/discuss/59700/Python-trie-solution-search-using-dfs 여기서 가져와서 보기좋게 가공했다. addWord로 단어가 추가되면 트라이를 구성하는데, 단어가 어떻게 구성되는지는 아래에 print MyPrettyPrinter().pformat(t.tri..

algorithm/theory 2020.06.08

leetcode 863(트리), 430(linked list, stack), 114, 211(구현, 정규식)

863 https://leetcode.com/problems/all-nodes-distance-k-in-binary-tree/ 1. 그래프 개념으로 어떤 한 노드에 연결된 모든 노드를 찾는다. 연결된 노드는 [부모, 왼쪽 자식, 오른쪽 자식]이다. 이것들을 node_list에 저장해놓는다. 2. 저장한 후에는 target을 시작점으로 [부모, 왼쪽 자식, 오른쪽 자식]을 돌면서 거리가 K인 노드들을 dfs로 탐색한다. from collections import deque class Solution(object): def distanceK(self, root, target, K): node_list = {} queue = deque([[root, None]]) # node, parent while queu..

leetcode 97(dfs), 767(구현, 힙), 991(구현), 650(dp)

97 https://leetcode.com/problems/interleaving-string/ dfs로 푼다. from collections import deque class Solution(object): def isInterleave(self, s1, s2, s3): s1_len, s2_len, s3_len = len(s1), len(s2), len(s3) if s1_len + s2_len != s3_len: return False stack = deque([[0, 0]]) visited = set() visited.add((0, 0)) while stack: p = stack.pop() if p[0] + p[1] == s3_len: return True if p[0] < s1_len and s1[..