Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
leon-inf committed Sep 8, 2023
1 parent d92ab74 commit a821c09
Show file tree
Hide file tree
Showing 2 changed files with 227 additions and 173 deletions.
105 changes: 58 additions & 47 deletions apis/apps/v1alpha1/builtin_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +14,70 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the apps v1alpha1 API group
package v1alpha1

type BuiltInVars string
// BuiltInVar represents a predefined system or environment variable that can be used within BuiltInString to
// provide dynamic and context-specific values when processed.
type BuiltInVar string

// BuiltInString defines a kind of string that may contain BuiltInVars within it.
// For this kind of string, we will replace all built-in vars with actual value before using it.
// BuiltInString defines a string type that may contain references to BuiltInVar placeholders.
// These placeholders are meant to be replaced with actual values at runtime to provide dynamic content.
type BuiltInString string

const (
// KB_RANDOM_PASSWD - random 8 characters
KB_RANDOM_PASSWD BuiltInVars = "$(KB_RANDOM_PASSWD)"

// KB_UUID - random UUID v4 string
KB_UUID BuiltInVars = "$(UUID)"
// KB_UUID_B64 - random UUID v4 BASE64 encoded string
KB_UUID_B64 BuiltInVars = "$(UUID_B64)"
// KB_UUID_STR_B64 - random UUID v4 string then BASE64 encoded
KB_UUID_STR_B64 BuiltInVars = "$(UUID_STR_B64)"
// KB_UUID_HEX - random UUID v4 HEX representation.
KB_UUID_HEX BuiltInVars = "$(UUID_HEX)"

// KB_SVC_FQDN - service FQDN placeholder, value pattern - $(CLUSTER_NAME)-$(1ST_COMP_NAME).$(NAMESPACE).svc,
// where 1ST_COMP_NAME is the 1st component that provide `ClusterDefinition.spec.componentDefs[].service` attribute
KB_SVC_FQDN BuiltInVars = "$(SVC_FQDN)"

// KB_HEADLESS_SVC_FQDN - headless service FQDN placeholder, value pattern - $(CLUSTER_NAME)-$(1ST_COMP_NAME)-headless.$(NAMESPACE).svc,
// where 1ST_COMP_NAME is the 1st component that provide `ClusterDefinition.spec.componentDefs[].service` attribute
KB_HEADLESS_SVC_FQDN BuiltInVars = "$(HEADLESS_SVC_FQDN)"

// KB_SVC_PORT - a ServicePort's port value with specified port name, i.e, a servicePort JSON struct:
// `{"name": "mysql", "targetPort": "mysqlContainerPort", "port": 3306}`, and "$(SVC_PORT_mysql)" will be rendered with value 3306.
KB_SVC_PORT BuiltInVars = "$(SVC_PORT_{PORT-NAME})"

KB_NAMESPACE BuiltInVars = "$(KB_NAMESPACE)"
KB_CLUSTER_NAME BuiltInVars = "$(KB_CLUSTER_NAME)"
KB_COMPONENT_NAME BuiltInVars = "$(KB_COMPONENT_NAME)"
KB_COMPONENT_REPLICAS BuiltInVars = "$(KB_COMPONENT_REPLICAS)"

KB_HOST_NAME BuiltInVars = "$(KB_HOST_NAME)"
KB_HOST_IP BuiltInVars = "$(KB_HOST_IP)"
KB_HOST_FQDN BuiltInVars = "$(KB_HOST_FQDN)"
KB_POD_NAME BuiltInVars = "$(KB_POD_NAME)"
KB_POD_IP BuiltInVars = "$(KB_POD_IP)"
KB_POD_FQDN BuiltInVars = "$(KB_POD_FQDN)"
KB_POD_ORDINAL BuiltInVars = "$(KB_POD_ORDINAL)"

KB_SERVICE_ENDPOINT BuiltInVars = "$(KB_SERVICE_ENDPOINT)"
KB_SERVICE_PORT BuiltInVars = "$(KB_SERVICE_PORT)"
KB_SERVICE_USER BuiltInVars = "$(KB_SERVICE_USER)"
KB_SERVICE_PASSWORD BuiltInVars = "$(KB_SERVICE_PASSWORD)"

KB_REPLICA_ROLE BuiltInVars = "$(KB_REPLICA_ROLE)"
// KB_RANDOM_PASSWD generates a random 8-character password.
KB_RANDOM_PASSWD BuiltInVar = "$(KB_RANDOM_PASSWD)"

// KB_UUID generates a random UUID v4 string.
KB_UUID BuiltInVar = "$(UUID)"

// KB_UUID_B64 generates a random UUID v4 and encode it in BASE64.
KB_UUID_B64 BuiltInVar = "$(UUID_B64)"

// KB_UUID_STR_B64 generates a random UUID v4 string, and encode it in BASE64.
KB_UUID_STR_B64 BuiltInVar = "$(UUID_STR_B64)"

// KB_UUID_HEX generates a random UUID v4 and represent it as a HEX string.
KB_UUID_HEX BuiltInVar = "$(UUID_HEX)"

// KB_SVC_FQDN placeholder for service FQDN value pattern - $(CLUSTER_NAME)-$(1ST_COMP_NAME).$(NAMESPACE).svc,
// where 1ST_COMP_NAME is the 1st component that provides the `ClusterDefinition.spec.componentDefs[].service` attribute.
KB_SVC_FQDN BuiltInVar = "$(SVC_FQDN)"

// KB_HEADLESS_SVC_FQDN placeholder for headless service FQDN value pattern - $(CLUSTER_NAME)-$(1ST_COMP_NAME)-headless.$(NAMESPACE).svc,
// where 1ST_COMP_NAME is the 1st component that provides the `ClusterDefinition.spec.componentDefs[].service` attribute.
KB_HEADLESS_SVC_FQDN BuiltInVar = "$(HEADLESS_SVC_FQDN)"

// KB_SVC_PORT references a ServicePort's port value with a specified port name.
// Example: {"name": "mysql", "targetPort": "mysqlContainerPort", "port": 3306}.
// Usage: $(SVC_PORT_mysql) will be rendered as 3306.
KB_SVC_PORT BuiltInVar = "$(SVC_PORT_{PORT-NAME})"

// KB_NAMESPACE references the namespace where the component is running.
KB_NAMESPACE BuiltInVar = "$(KB_NAMESPACE)"

// KB_CLUSTER_NAME references the name of the cluster.
KB_CLUSTER_NAME BuiltInVar = "$(KB_CLUSTER_NAME)"

// KB_COMPONENT_NAME references the name of the component.
KB_COMPONENT_NAME BuiltInVar = "$(KB_COMPONENT_NAME)"

// KB_COMPONENT_REPLICAS references the number of replicas for the component.
KB_COMPONENT_REPLICAS BuiltInVar = "$(KB_COMPONENT_REPLICAS)"

KB_HOST_NAME BuiltInVar = "$(KB_HOST_NAME)"
KB_HOST_IP BuiltInVar = "$(KB_HOST_IP)"
KB_HOST_FQDN BuiltInVar = "$(KB_HOST_FQDN)"
KB_POD_NAME BuiltInVar = "$(KB_POD_NAME)"
KB_POD_IP BuiltInVar = "$(KB_POD_IP)"
KB_POD_FQDN BuiltInVar = "$(KB_POD_FQDN)"
KB_POD_ORDINAL BuiltInVar = "$(KB_POD_ORDINAL)"

KB_SERVICE_ENDPOINT BuiltInVar = "$(KB_SERVICE_ENDPOINT)"
KB_SERVICE_PORT BuiltInVar = "$(KB_SERVICE_PORT)"

// KB_REPLICA_ROLE references the role of the replica (e.g., leader, follower).
KB_REPLICA_ROLE BuiltInVar = "$(KB_REPLICA_ROLE)"

// TODO: built-in operators, i.e, length, symbol/digit, lower/upper - for password
)
Loading

0 comments on commit a821c09

Please sign in to comment.