Skip to content

Commit

Permalink
return to local copy
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT committed Apr 26, 2024
1 parent fbd3ea9 commit c7a1b89
Show file tree
Hide file tree
Showing 9 changed files with 785 additions and 30 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ jobs:
steps:
- name: Check out code
uses: actions/checkout@v4
with:
submodules: recursive

- uses: actions/setup-go@v4
with:
Expand Down
9 changes: 0 additions & 9 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ jobs:

- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: Unit Test
run: make unit-test
Expand All @@ -62,9 +59,6 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@master
Expand Down Expand Up @@ -113,9 +107,6 @@ jobs:
go-version: ${{ env.DEFAULT_GO_VERSION }}
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: Download image
uses: actions/download-artifact@v3
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ jobs:
uses: actions/checkout@v4
with:
ref: ${{ needs.release-please.outputs.release_tag_name }}
submodules: recursive
fetch-depth: 0

- name: Log in to the Container registry
uses: docker/login-action@a9794064588be971151ec5e7144cb535bcb56e36
Expand Down Expand Up @@ -118,8 +116,6 @@ jobs:
uses: actions/checkout@v4
with:
ref: ${{ needs.release-please.outputs.release_tag_name }}
submodules: recursive
fetch-depth: 0

- name: Setup go
uses: actions/setup-go@v4
Expand Down Expand Up @@ -156,7 +152,6 @@ jobs:
with:
fetch-depth: 0
ref: ${{ env.GITHUB_PAGES_BRANCH }}
submodules: recursive

- name: Setup go
uses: actions/setup-go@v4
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ RUN go mod download
# Copy the go source
COPY main.go main.go
COPY apis/ apis/
COPY apis/flagd-schemas/ apis/flagd-schemas/
COPY webhooks/ webhooks/
COPY controllers/ controllers/
COPY common/ common/
Expand Down
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CHART_VERSION=v0.5.4# x-release-please-version
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.26.1
WAIT_TIMEOUT_SECONDS?=60
PUBLIC_JSON_SCHEMA_DIR=apis/core/v1beta1/schema

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -256,3 +257,14 @@ install-mockgen:
go install github.com/golang/mock/[email protected]
mockgen: install-mockgen
mockgen -source=controllers/common/flagd-injector.go -destination=controllers/common/mock/flagd-injector.go -package=commonmock

.PHONY: pull-schemas-submodule
pull-schemas-submodule:
git submodule update

# Update the schema at flagd.dev
# PUBLIC_JSON_SCHEMA_DIR above controls the dir (and therefore major version)
.PHONY: update-public-schema
update-public-schema: pull-schemas-submodule
rm -f $(PUBLIC_JSON_SCHEMA_DIR)*.json
cp apis/flagd-schemas/json/*.json $(PUBLIC_JSON_SCHEMA_DIR)
20 changes: 7 additions & 13 deletions apis/core/v1beta1/featureflag_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package v1beta1
import (
"encoding/json"
"fmt"
"os"

_ "embed"

Expand All @@ -33,7 +32,11 @@ import (
// log is for logging in this package.
var featureflaglog = logf.Log.WithName("featureflag-resource")

const SchemaPath = "./../../flagd-schemas/json/"
//go:embed schema/targeting.json
var TargetingSchema string

//go:embed schema/flags.json
var FlagsScheme string

func (ff *FeatureFlag) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
Expand Down Expand Up @@ -102,18 +105,9 @@ func validateFeatureFlagFlags(flags Flags) error {
}

func initSchemas() (*gojsonschema.Schema, error) {
targetingSchema, err := os.ReadFile(SchemaPath + "targeting.json")
if err != nil {
return nil, err
}
flagsScheme, err := os.ReadFile(SchemaPath + "flags.json")
if err != nil {
return nil, err
}

schemaLoader := gojsonschema.NewSchemaLoader()
schemaLoader.AddSchemas(gojsonschema.NewStringLoader(string(targetingSchema)))
compiledSchema, err := schemaLoader.Compile(gojsonschema.NewStringLoader(string(flagsScheme)))
schemaLoader.AddSchemas(gojsonschema.NewStringLoader(TargetingSchema))
compiledSchema, err := schemaLoader.Compile(gojsonschema.NewStringLoader(FlagsScheme))
if err != nil {
return nil, err
}
Expand Down
Empty file.
184 changes: 184 additions & 0 deletions apis/core/v1beta1/schema/flags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
{
"$id": "https://flagd.dev/schema/v0/flags.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "flagd Flag Configuration",
"description": "Defines flags for use in flagd, including typed variants and rules",
"type": "object",
"properties": {
"flags": {
"title": "Flags",
"description": "Top-level flags object. All flags are defined here.",
"type": "object",
"$comment": "flag objects are one of the 4 flag types defined in $defs",
"additionalProperties": false,
"patternProperties": {
"^.{1,}$": {
"oneOf": [
{
"title": "Boolean flag",
"description": "A flag having boolean values.",
"$ref": "#/$defs/booleanFlag"
},
{
"title": "String flag",
"description": "A flag having string values.",
"$ref": "#/$defs/stringFlag"
},
{
"title": "Numeric flag",
"description": "A flag having numeric values.",
"$ref": "#/$defs/numberFlag"
},
{
"title": "Object flag",
"description": "A flag having arbitrary object values.",
"$ref": "#/$defs/objectFlag"
}
]
}
}
},
"$evaluators": {
"title": "Evaluators",
"description": "Reusable targeting rules that can be referenced with \"$ref\": \"myRule\" in multiple flags.",
"type": "object",
"additionalProperties": false,
"patternProperties": {
"^.{1,}$": {
"$comment": "this relative ref means that targeting.json MUST be in the same dir, or available on the same HTTP path",
"$ref": "./targeting.json#/$defs/targeting"
}
}
}
},
"$defs": {
"flag": {
"$comment": "base flag object; no title/description here, allows for better UX, keep it in the overrides",
"type": "object",
"properties": {
"state": {
"title": "Flag State",
"description": "Indicates whether the flag is functional. Disabled flags are treated as if they don't exist.",
"type": "string",
"enum": [
"ENABLED",
"DISABLED"
]
},
"defaultVariant": {
"title": "Default Variant",
"description": "The variant to serve if no dynamic targeting applies (including if the targeting returns null).",
"type": "string"
},
"targeting": {
"$ref": "./targeting.json#/$defs/targeting"
}
},
"required": [
"state",
"defaultVariant"
]
},
"booleanVariants": {
"type": "object",
"properties": {
"variants": {
"type": "object",
"additionalProperties": false,
"patternProperties": {
"^.{1,}$": {
"type": "boolean"
}
},
"default": {
"true": true,
"false": false
}
}
}
},
"stringVariants": {
"type": "object",
"properties": {
"variants": {
"type": "object",
"additionalProperties": false,
"patternProperties": {
"^.{1,}$": {
"type": "string"
}
}
}
}
},
"numberVariants": {
"type": "object",
"properties": {
"variants": {
"type": "object",
"additionalProperties": false,
"patternProperties": {
"^.{1,}$": {
"type": "number"
}
}
}
}
},
"objectVariants": {
"type": "object",
"properties": {
"variants": {
"type": "object",
"additionalProperties": false,
"patternProperties": {
"^.{1,}$": {
"type": "object"
}
}
}
}
},
"$comment": "merge the variants with the base flag to build our typed flags",
"booleanFlag": {
"allOf": [
{
"$ref": "#/$defs/flag"
},
{
"$ref": "#/$defs/booleanVariants"
}
]
},
"stringFlag": {
"allOf": [
{
"$ref": "#/$defs/flag"
},
{
"$ref": "#/$defs/stringVariants"
}
]
},
"numberFlag": {
"allOf": [
{
"$ref": "#/$defs/flag"
},
{
"$ref": "#/$defs/numberVariants"
}
]
},
"objectFlag": {
"allOf": [
{
"$ref": "#/$defs/flag"
},
{
"$ref": "#/$defs/objectVariants"
}
]
}
}
}
Loading

0 comments on commit c7a1b89

Please sign in to comment.