Skip to content

Commit 8f0d6bb

Browse files
committed
[patch] Add openshift package removal plan
1 parent bded81d commit 8f0d6bb

1 file changed

Lines changed: 257 additions & 0 deletions

File tree

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
# Migrate from openshift to Kubernetes Python Client
2+
3+
## Objective
4+
5+
Replace the `openshift` package with the official `kubernetes` Python client's `DynamicClient` in the MAS CLI codebase to ensure better maintenance, broader community support, and eliminate dependency on the OpenShift-specific client library.
6+
7+
## Critical Rules
8+
9+
- Maintain backward compatibility - all function signatures must remain unchanged
10+
- All existing tests must pass without modification
11+
- No `.apply()` method usage found in CLI codebase (simpler migration than python-devops)
12+
- Validate with `black` and `flake8` after each code change
13+
- Update copyright headers to 2026 where files are modified
14+
- Test incrementally - validate each file after refactoring
15+
- The CLI depends on `mas-devops >= 5.2.0` which must be migrated first
16+
17+
## Execution Plan
18+
19+
### Phase 1: Analysis and Preparation
20+
21+
- [ ] **1.1** Document all usage patterns of `openshift.dynamic`
22+
- [ ] `DynamicClient` instantiation (4 files: cli.py, validators.py, 2 test helpers)
23+
- [ ] Exception types: `NotFoundError`, `ResourceNotFoundError`
24+
- [ ] No `.apply()` calls found (unlike python-devops)
25+
- [ ] Import in validators.py has comment about needing apply (line 16-17)
26+
27+
- [ ] **1.2** Verify mas-devops dependency status
28+
- [ ] Confirm mas-devops has completed openshift → kubernetes migration
29+
- [ ] Update mas-devops version requirement if needed
30+
31+
- [ ] **1.3** Validate Phase 1
32+
- [ ] All openshift usage patterns documented
33+
- [ ] Dependency chain understood
34+
35+
### Phase 2: Update Dependencies
36+
37+
- [ ] **2.1** Update [`python/setup.py`](python/setup.py:60) dependencies
38+
- [ ] Remove `'openshift'` from install_requires (line 60)
39+
- [ ] Ensure `'kubernetes == 33.1.0'` remains (line 61)
40+
- [ ] Update mas-devops version if needed (line 56)
41+
42+
- [ ] **2.2** Update copyright header in setup.py
43+
- [ ] Change copyright year from 2024 to 2024, 2026
44+
45+
- [ ] **2.3** Validate Phase 2
46+
- [ ] Run `python setup.py check`
47+
- [ ] Verify no syntax errors
48+
49+
### Phase 3: Update Source Code Imports
50+
51+
- [ ] **3.1** Update [`python/src/mas/cli/validators.py`](python/src/mas/cli/validators.py:17)
52+
- [ ] Replace `from openshift import dynamic` with `from kubernetes import dynamic`
53+
- [ ] Remove or update comment about needing apply (line 16)
54+
- [ ] Update copyright header to include 2026
55+
56+
- [ ] **3.2** Update [`python/src/mas/cli/cli.py`](python/src/mas/cli/cli.py:28-29)
57+
- [ ] Replace `from openshift.dynamic import DynamicClient` with `from kubernetes.dynamic import DynamicClient`
58+
- [ ] Replace `from openshift.dynamic.exceptions import NotFoundError` with `from kubernetes.dynamic.exceptions import NotFoundError`
59+
- [ ] Update copyright header to include 2026
60+
61+
- [ ] **3.3** Update [`python/src/mas/cli/install/app.py`](python/src/mas/cli/install/app.py:20)
62+
- [ ] Replace `from openshift.dynamic.exceptions import NotFoundError` with `from kubernetes.dynamic.exceptions import NotFoundError`
63+
- [ ] Update copyright header to include 2026
64+
65+
- [ ] **3.4** Update [`python/src/mas/cli/install/settings/manageSettings.py`](python/src/mas/cli/install/settings/manageSettings.py:15,26)
66+
- [ ] Replace `from openshift.dynamic.exceptions import ResourceNotFoundError` with `from kubernetes.dynamic.exceptions import ResourceNotFoundError`
67+
- [ ] Replace `from openshift.dynamic import DynamicClient` (TYPE_CHECKING block) with `from kubernetes.dynamic import DynamicClient`
68+
- [ ] Update copyright header to include 2026
69+
70+
- [ ] **3.5** Update [`python/src/mas/cli/install/summarizer.py`](python/src/mas/cli/install/summarizer.py:26)
71+
- [ ] Replace `from openshift.dynamic import DynamicClient` (TYPE_CHECKING block) with `from kubernetes.dynamic import DynamicClient`
72+
- [ ] Update copyright header to include 2026
73+
74+
- [ ] **3.6** Update [`python/src/mas/cli/update/app.py`](python/src/mas/cli/update/app.py:19)
75+
- [ ] Replace `from openshift.dynamic.exceptions import NotFoundError, ResourceNotFoundError` with `from kubernetes.dynamic.exceptions import NotFoundError, ResourceNotFoundError`
76+
- [ ] Update copyright header to include 2026
77+
78+
- [ ] **3.7** Update [`python/src/mas/cli/uninstall/app.py`](python/src/mas/cli/uninstall/app.py:18)
79+
- [ ] Replace `from openshift.dynamic.exceptions import NotFoundError, ResourceNotFoundError` with `from kubernetes.dynamic.exceptions import NotFoundError, ResourceNotFoundError`
80+
- [ ] Update copyright header to include 2026
81+
82+
- [ ] **3.8** Update [`python/src/mas/cli/backup/app.py`](python/src/mas/cli/backup/app.py:18)
83+
- [ ] Replace `from openshift.dynamic.exceptions import ResourceNotFoundError` with `from kubernetes.dynamic.exceptions import ResourceNotFoundError`
84+
- [ ] Update copyright header to include 2026
85+
86+
- [ ] **3.9** Update [`python/src/mas/cli/aiservice/install/app.py`](python/src/mas/cli/aiservice/install/app.py:20)
87+
- [ ] Replace `from openshift.dynamic.exceptions import NotFoundError` with `from kubernetes.dynamic.exceptions import NotFoundError`
88+
- [ ] Update copyright header to include 2026
89+
90+
- [ ] **3.10** Update [`python/src/mas/cli/aiservice/upgrade/app.py`](python/src/mas/cli/aiservice/upgrade/app.py:27)
91+
- [ ] Replace `from openshift.dynamic.exceptions import ResourceNotFoundError` with `from kubernetes.dynamic.exceptions import ResourceNotFoundError`
92+
- [ ] Update copyright header to include 2026
93+
94+
- [ ] **3.11** Validate Phase 3
95+
- [ ] Run `wsl bash -lc "black python/src/mas/cli/*.py python/src/mas/cli/**/*.py"`
96+
- [ ] Run `wsl bash -lc "flake8 python/src/mas/cli/*.py python/src/mas/cli/**/*.py"`
97+
- [ ] Verify no import errors
98+
99+
### Phase 4: Update Test Code Imports
100+
101+
- [ ] **4.1** Update [`python/test/utils/install_test_helper.py`](python/test/utils/install_test_helper.py:18-19)
102+
- [ ] Replace `from openshift.dynamic import DynamicClient` with `from kubernetes.dynamic import DynamicClient`
103+
- [ ] Replace `from openshift.dynamic.exceptions import NotFoundError` with `from kubernetes.dynamic.exceptions import NotFoundError`
104+
- [ ] Update copyright header to include 2026
105+
106+
- [ ] **4.2** Update [`python/test/utils/update_test_helper.py`](python/test/utils/update_test_helper.py:18)
107+
- [ ] Replace `from openshift.dynamic import DynamicClient` with `from kubernetes.dynamic import DynamicClient`
108+
- [ ] Update copyright header to include 2026
109+
110+
- [ ] **4.3** Update [`python/test/aiservice/install/test_app.py`](python/test/aiservice/install/test_app.py:16-17)
111+
- [ ] Replace `from openshift.dynamic import DynamicClient` with `from kubernetes.dynamic import DynamicClient`
112+
- [ ] Replace `from openshift.dynamic.exceptions import NotFoundError` with `from kubernetes.dynamic.exceptions import NotFoundError`
113+
- [ ] Update copyright header to include 2026
114+
115+
- [ ] **4.4** Validate Phase 4
116+
- [ ] Run `wsl bash -lc "black python/test/**/*.py"`
117+
- [ ] Run `wsl bash -lc "flake8 python/test/**/*.py"`
118+
- [ ] Verify no syntax errors
119+
120+
### Phase 5: Testing
121+
122+
- [ ] **5.1** Run existing test suite
123+
- [ ] Run `wsl bash -lc "cd python && pytest test/ -v"`
124+
- [ ] Document any failures and root cause
125+
- [ ] Fix any issues found
126+
127+
- [ ] **5.2** Validate Phase 5
128+
- [ ] All existing tests pass
129+
- [ ] No regressions detected
130+
131+
### Phase 6: Final Validation
132+
133+
- [ ] **6.1** Code quality checks
134+
- [ ] Run `wsl bash -lc "black python/src/mas/cli/*.py python/src/mas/cli/**/*.py python/test/**/*.py"`
135+
- [ ] Run `wsl bash -lc "flake8 python/src/mas/cli/*.py python/src/mas/cli/**/*.py python/test/**/*.py"`
136+
- [ ] Verify no violations
137+
138+
- [ ] **6.2** Dependency verification
139+
- [ ] Run `python python/setup.py check`
140+
- [ ] Verify `openshift` is not in dependencies
141+
- [ ] Verify `kubernetes` is in dependencies
142+
- [ ] Verify mas-devops version is correct
143+
144+
- [ ] **6.3** Documentation review
145+
- [ ] All copyright headers include 2026
146+
- [ ] No references to openshift package remain
147+
- [ ] Comment in validators.py about apply is updated/removed
148+
149+
## Implementation Details
150+
151+
### Files Requiring Changes
152+
153+
**Source Code (10 files):**
154+
1. [`python/src/mas/cli/validators.py`](python/src/mas/cli/validators.py:17) - Main import + comment
155+
2. [`python/src/mas/cli/cli.py`](python/src/mas/cli/cli.py:28-29) - DynamicClient + NotFoundError
156+
3. [`python/src/mas/cli/install/app.py`](python/src/mas/cli/install/app.py:20) - NotFoundError
157+
4. [`python/src/mas/cli/install/settings/manageSettings.py`](python/src/mas/cli/install/settings/manageSettings.py:15,26) - ResourceNotFoundError + TYPE_CHECKING
158+
5. [`python/src/mas/cli/install/summarizer.py`](python/src/mas/cli/install/summarizer.py:26) - TYPE_CHECKING
159+
6. [`python/src/mas/cli/update/app.py`](python/src/mas/cli/update/app.py:19) - Both exceptions
160+
7. [`python/src/mas/cli/uninstall/app.py`](python/src/mas/cli/uninstall/app.py:18) - Both exceptions
161+
8. [`python/src/mas/cli/backup/app.py`](python/src/mas/cli/backup/app.py:18) - ResourceNotFoundError
162+
9. [`python/src/mas/cli/aiservice/install/app.py`](python/src/mas/cli/aiservice/install/app.py:20) - NotFoundError
163+
10. [`python/src/mas/cli/aiservice/upgrade/app.py`](python/src/mas/cli/aiservice/upgrade/app.py:27) - ResourceNotFoundError
164+
165+
**Test Code (3 files):**
166+
1. [`python/test/utils/install_test_helper.py`](python/test/utils/install_test_helper.py:18-19)
167+
2. [`python/test/utils/update_test_helper.py`](python/test/utils/update_test_helper.py:18)
168+
3. [`python/test/aiservice/install/test_app.py`](python/test/aiservice/install/test_app.py:16-17)
169+
170+
**Configuration (1 file):**
171+
1. [`python/setup.py`](python/setup.py:60) - Remove openshift dependency
172+
173+
### Import Replacement Patterns
174+
175+
**Pattern 1: DynamicClient only**
176+
```python
177+
# Before
178+
from openshift.dynamic import DynamicClient
179+
180+
# After
181+
from kubernetes.dynamic import DynamicClient
182+
```
183+
184+
**Pattern 2: NotFoundError only**
185+
```python
186+
# Before
187+
from openshift.dynamic.exceptions import NotFoundError
188+
189+
# After
190+
from kubernetes.dynamic.exceptions import NotFoundError
191+
```
192+
193+
**Pattern 3: ResourceNotFoundError only**
194+
```python
195+
# Before
196+
from openshift.dynamic.exceptions import ResourceNotFoundError
197+
198+
# After
199+
from kubernetes.dynamic.exceptions import ResourceNotFoundError
200+
```
201+
202+
**Pattern 4: Both exceptions**
203+
```python
204+
# Before
205+
from openshift.dynamic.exceptions import NotFoundError, ResourceNotFoundError
206+
207+
# After
208+
from kubernetes.dynamic.exceptions import NotFoundError, ResourceNotFoundError
209+
```
210+
211+
**Pattern 5: Dynamic module (validators.py)**
212+
```python
213+
# Before
214+
from openshift import dynamic
215+
216+
# After
217+
from kubernetes import dynamic
218+
```
219+
220+
### Special Considerations
221+
222+
1. **No apply() usage**: Unlike python-devops, the CLI codebase does not use `.apply()` method, making this migration simpler
223+
2. **Comment in validators.py**: Line 16-17 mentions using openshift for apply access - this comment should be removed or updated
224+
3. **Dependency on mas-devops**: The CLI requires `mas-devops >= 5.2.0` which must complete its migration first
225+
4. **TYPE_CHECKING blocks**: Two files use TYPE_CHECKING imports that also need updating
226+
227+
## Validation
228+
229+
### Success Criteria
230+
231+
1. **Dependency removed**: `openshift` no longer in [`python/setup.py`](python/setup.py:60)
232+
2. **Imports updated**: All 13 files use `kubernetes.dynamic` instead of `openshift.dynamic`
233+
3. **Code quality**: All files pass `black` and `flake8` validation
234+
4. **Tests pass**: All existing tests pass without modification
235+
5. **Copyright updated**: Modified files have 2026 in copyright header
236+
6. **Comment updated**: validators.py comment about apply is removed/updated
237+
238+
### Commands to Run
239+
240+
```bash
241+
# Code formatting and linting
242+
wsl bash -lc "black python/src/mas/cli/*.py python/src/mas/cli/**/*.py python/test/**/*.py"
243+
wsl bash -lc "flake8 python/src/mas/cli/*.py python/src/mas/cli/**/*.py python/test/**/*.py"
244+
245+
# Run all tests
246+
wsl bash -lc "cd python && pytest test/ -v"
247+
248+
# Verify setup.py
249+
python python/setup.py check
250+
```
251+
252+
### Expected Results
253+
254+
- Black: No files reformatted
255+
- Flake8: No violations
256+
- Pytest: All tests pass
257+
- Setup.py: No errors, `openshift` not in dependencies

0 commit comments

Comments
 (0)