CLI 명령을 작성할 수 있는 모든 프로그래밍 언어 또는 스크립트로 플러그인을 작성할 수 있습니다. 플러그인이 반드시 바이너리 구성 요소를 보유할 필요는 없습니다. echo,sed 또는 grep 과 같은 운영 체제 유틸리티에 전적으로 의존할 수 있습니다. 또는 oc 바이너리를 사용할 수 있습니다.
oc 플러그인의 유일한 강력한 요구 사항은 plugin.yaml 설명자 파일입니다. 이 파일은 플러그인 등록에 필요한 최소 특성을 선언해야 하며, Search Order 섹션에 지정된 위치 중 하나에 위치해야 합니다.
name: "great-plugin" # REQUIRED: the plug-in command name, to be invoked under 'kubectl'
shortDesc: "great-plugin plug-in" # REQUIRED: the command short description, for help
longDesc: "" # the command long description, for help
example: "" # command example(s), for help
command: "./example" # REQUIRED: the command, binary, or script to invoke when running the plug-in
flags: # flags supported by the plug-in
- name: "flag-name" # REQUIRED for each flag: flag name
shorthand: "f" # short version of the flag name
desc: "example flag" # REQUIRED for each flag: flag description
defValue: "extreme" # default value of the flag
tree: # allows the declaration of subcommands
- ... # subcommands support the same set of attributes
name: "great-plugin" # REQUIRED: the plug-in command name, to be invoked under 'kubectl'
shortDesc: "great-plugin plug-in" # REQUIRED: the command short description, for help
longDesc: "" # the command long description, for help
example: "" # command example(s), for help
command: "./example" # REQUIRED: the command, binary, or script to invoke when running the plug-in
flags: # flags supported by the plug-in
- name: "flag-name" # REQUIRED for each flag: flag name
shorthand: "f" # short version of the flag name
desc: "example flag" # REQUIRED for each flag: flag description
defValue: "extreme" # default value of the flag
tree: # allows the declaration of subcommands
- ... # subcommands support the same set of attributes
Copy to ClipboardCopied!Toggle word wrapToggle overflow
앞의 설명자는 -f | --flag-name 이라는 하나의 플래그가 있는 great-plugin 플러그인을 선언합니다. 다음과 같이 호출할 수 있습니다.
oc plugin great-plugin -f value
$oc plugin great-plugin -f value
Copy to ClipboardCopied!Toggle word wrapToggle overflow
플러그인이 호출되면 설명자 파일과 동일한 디렉터리에 있는 예제 바이너리 또는 스크립트를 호출하여 여러 인수 및 환경 변수를 전달합니다. 액세스 런타임 속성 섹션에서는 example 명령이 플래그 값과 기타 런타임 컨텍스트에 액세스하는 방법을 설명합니다.