This is the OpenShift Console CronTab Plugin, a dynamic plugin for the OpenShift web console that enables management of CronTab custom resources (CRDs). The plugin demonstrates basic CRD operations including create, read, update, and delete (CRUD) functionality, integrating seamlessly with the OpenShift console UI.
- Language: TypeScript
- Framework: React
- UI Library: PatternFly React components
- Build Tool: Webpack
- Plugin SDK: @openshift-console/dynamic-plugin-sdk
- Testing: Cypress for E2E integration tests
- Internationalization: react-i18next, i18next-parser
- Styling: Sass/SCSS with PatternFly styles
- Linting: ESLint with TypeScript, React, and Prettier plugins
-
Dynamic Plugin Architecture: Uses OpenShift Console's dynamic plugin system with exposed modules defined in
package.jsonunderconsolePlugin.exposedModules -
TypeScript Path Aliases:
@crontab-utils→src/utils@crontab-model→src/types
-
Component Structure: Functional React components with hooks (no class components)
-
Data Types: CronTab CRD structure defined in
src/types/types.ts:type CronTabKind = K8sResourceCommon & { spec?: { cronSpec: string; // Cron schedule format image: string; // Container image replicas: number; // Number of replicas }; };
-
Internationalization: All user-facing strings must use the translation hook (
useCronTabTranslation) from@crontab-utils/hooks
# Install dependencies
yarn install
# Start development server (runs on port 9001)
yarn start
# In another terminal, start OpenShift console (requires oc login first)
yarn start-console# Type checking
yarn check-types
# Production build
yarn build
# Build Docker image
docker build -f Dockerfile -t <registry>/console-crontab-plugin:latest .
# Push to registry
docker push <registry>/console-crontab-plugin:latestNote for Apple Silicon: Add --platform=linux/amd64 flag when building Docker images
# Extract and build i18n resources
yarn i18nLocated in integration-tests/ directory with the following structure:
e2e/- Test specificationssupport/- Helper utilities and custom commandsviews/- Page object modelsfixtures/- Test data
# Interactive Cypress test runner
yarn test-cypress
# Headless test execution
yarn test-cypress-headless- Target: ES2016
- Module: ESNext with Node resolution
- JSX: React
- Strict Options:
noUnusedLocals: true - Source Maps: Enabled
-
Components:
- Use functional components with TypeScript
- Prefer React hooks over class components
- Props should have TypeScript interfaces/types
- Export default for main component
-
Imports:
- Use absolute imports with path aliases when possible
- Group imports: React/external libs, SDK imports, local imports
- Example from
CronTabList.tsx:import React from "react"; import { CronTabKind } from "@crontab-model/types"; import { useCronTabTranslation } from "@crontab-utils/hooks/useCronTabTranslation";
-
Naming Conventions:
- Components: PascalCase (e.g.,
CronTabList) - Files: Match component name (e.g.,
CronTabList.tsx) - Hooks: camelCase with
useprefix (e.g.,useCronTabTranslation) - Constants: UPPER_SNAKE_CASE (e.g.,
CRONTAB_KIND_PLURAL) - Test IDs: kebab-case with
data-testordata-test-idattributes
- Components: PascalCase (e.g.,
-
Internationalization:
- All user-facing strings MUST be wrapped with
t()function - Use the
useCronTabTranslationhook for translations - Example:
t("Create CronTab") - Default namespace:
plugin__console-crontab-plugin
- All user-facing strings MUST be wrapped with
-
State Management:
- Use OpenShift SDK hooks like
useK8sWatchResource,useListPageFilter - Local state with
React.useState - Memoization with
React.useMemoandReact.useCallbackwhen appropriate
- Use OpenShift SDK hooks like
- File Naming:
*.cy.tsfor Cypress specs - Page Objects: Use view models in
integration-tests/views/ - Test Structure: Follow arrange-act-assert pattern
- Selectors: Use
cy.byTestID()andcy.byTestSelector()custom commands - Setup/Teardown: Use
before/afterhooks for project setup
helm upgrade -i console-crontab-plugin \
charts/console-crontab-plugin \
-n console-crontab-plugin-ns \
--create-namespace \
--set plugin.image=docker.io/<registry>/console-crontab-plugin:latestThe Dockerfile uses a multi-stage build:
- Build stage: Node.js on UBI9, runs
yarn install && yarn build - Runtime stage: Nginx on UBI8, serves static files from
/dist
-
Do Not Modify:
package.jsonconsolePluginsection without understanding plugin architecture- Webpack configuration without testing local dev server
- i18n configuration without running
yarn i18nafterward
-
Before Making Changes:
- Run
yarn check-typesto verify TypeScript compilation - Run
yarn lintto check code style - Consider i18n impact - new user-facing strings need translations
- Run
-
When Adding New Features:
- Add TypeScript types to
src/types/ - Create new views in
src/views/ - Export components in exposed modules if needed by console
- Add corresponding Cypress tests
- Update i18n keys
- Add TypeScript types to
-
Common Gotchas:
- Plugin requires OpenShift console to be running for testing
- Path aliases must match
tsconfig.jsonandwebpack.config.ts - Console SDK hooks require specific resource formats