Skip to content

Commit

Permalink
apis: add a way to disable a resource only if every config map is dis…
Browse files Browse the repository at this point in the history
…abled (#5643)
  • Loading branch information
nicks committed Mar 30, 2022
1 parent 596dbcb commit e1dfe53
Show file tree
Hide file tree
Showing 8 changed files with 681 additions and 560 deletions.
19 changes: 18 additions & 1 deletion internal/tiltfile/v1alpha1/types.go
Expand Up @@ -595,21 +595,29 @@ type DisableSource struct {

func (p Plugin) disableSource(t *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
var configMap starlark.Value
var everyConfigMap starlark.Value
err := starkit.UnpackArgs(t, fn.Name(), args, kwargs,
"config_map?", &configMap,
"every_config_map?", &everyConfigMap,
)
if err != nil {
return nil, err
}

dict := starlark.NewDict(1)
dict := starlark.NewDict(2)

if configMap != nil {
err := dict.SetKey(starlark.String("config_map"), configMap)
if err != nil {
return nil, err
}
}
if everyConfigMap != nil {
err := dict.SetKey(starlark.String("every_config_map"), everyConfigMap)
if err != nil {
return nil, err
}
}
var obj *DisableSource = &DisableSource{t: t}
err = obj.Unpack(dict)
if err != nil {
Expand Down Expand Up @@ -648,6 +656,15 @@ func (o *DisableSource) Unpack(v starlark.Value) error {
obj.ConfigMap = (*v1alpha1.ConfigMapDisableSource)(&v.Value)
continue
}
if key == "every_config_map" {
v := ConfigMapDisableSourceList{t: o.t}
err := v.Unpack(val)
if err != nil {
return fmt.Errorf("unpacking %s: %v", key, err)
}
obj.EveryConfigMap = v.Value
continue
}
return fmt.Errorf("Unexpected attribute name: %s", key)
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/apis/core/v1alpha1/disable_types.go
Expand Up @@ -4,8 +4,12 @@ import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

// Points at a thing that can control whether something is disabled
type DisableSource struct {
// This DisableSource is controlled by a ConfigMap
// Disabled by single ConfigMap value.
ConfigMap *ConfigMapDisableSource `json:"configMap,omitempty" protobuf:"bytes,2,opt,name=configMap"`

// Disabled by multiple ConfigMap values, which must all be set to disabled
// to disable the object.
EveryConfigMap []ConfigMapDisableSource `json:"everyConfigMap,omitempty" protobuf:"bytes,3,rep,name=everyConfigMap"`
}

// Specifies a ConfigMap to control a DisableSource
Expand Down
1,172 changes: 617 additions & 555 deletions pkg/apis/core/v1alpha1/generated.pb.go

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion pkg/apis/core/v1alpha1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/apis/core/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion pkg/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion pkg/webview/view.swagger.json
Expand Up @@ -479,7 +479,14 @@
"properties": {
"configMap": {
"$ref": "#/definitions/v1alpha1ConfigMapDisableSource",
"title": "This DisableSource is controlled by a ConfigMap"
"description": "Disabled by single ConfigMap value."
},
"everyConfigMap": {
"type": "array",
"items": {
"$ref": "#/definitions/v1alpha1ConfigMapDisableSource"
},
"description": "Disabled by multiple ConfigMap values, which must all be set to disabled\nto disable the object."
}
},
"title": "Points at a thing that can control whether something is disabled"
Expand Down
8 changes: 8 additions & 0 deletions web/src/view.d.ts
Expand Up @@ -762,7 +762,15 @@ declare namespace Proto {
host?: string;
}
export interface v1alpha1DisableSource {
/**
* Disabled by single ConfigMap value.
*/
configMap?: v1alpha1ConfigMapDisableSource;
/**
* Disabled by multiple ConfigMap values, which must all be set to disabled
* to disable the object.
*/
everyConfigMap?: v1alpha1ConfigMapDisableSource[];
}
export interface v1alpha1DisableResourceStatus {
/**
Expand Down

0 comments on commit e1dfe53

Please sign in to comment.