Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable status subresource for voyager crds #394

Merged
merged 1 commit into from
Jul 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions apis/monitoring/v1alpha1/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import (
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
)

var (
EnableStatusSubresource bool
)

func (a ClusterAlert) CustomResourceDefinition() *apiextensions.CustomResourceDefinition {
return crdutils.NewCustomResourceDefinition(crdutils.Config{
Group: SchemeGroupVersion.Group,
Expand All @@ -17,9 +21,10 @@ func (a ClusterAlert) CustomResourceDefinition() *apiextensions.CustomResourceDe
Labels: crdutils.Labels{
LabelsMap: map[string]string{"app": "searchlight"},
},
SpecDefinitionName: "github.com/appscode/searchlight/apis/monitoring/v1alpha1.ClusterAlert",
EnableValidation: true,
GetOpenAPIDefinitions: GetOpenAPIDefinitions,
SpecDefinitionName: "github.com/appscode/searchlight/apis/monitoring/v1alpha1.ClusterAlert",
EnableValidation: true,
GetOpenAPIDefinitions: GetOpenAPIDefinitions,
EnableStatusSubresource: EnableStatusSubresource,
})
}

Expand All @@ -35,9 +40,10 @@ func (a NodeAlert) CustomResourceDefinition() *apiextensions.CustomResourceDefin
Labels: crdutils.Labels{
LabelsMap: map[string]string{"app": "searchlight"},
},
SpecDefinitionName: "github.com/appscode/searchlight/apis/monitoring/v1alpha1.NodeAlert",
EnableValidation: true,
GetOpenAPIDefinitions: GetOpenAPIDefinitions,
SpecDefinitionName: "github.com/appscode/searchlight/apis/monitoring/v1alpha1.NodeAlert",
EnableValidation: true,
GetOpenAPIDefinitions: GetOpenAPIDefinitions,
EnableStatusSubresource: EnableStatusSubresource,
})
}

Expand All @@ -53,9 +59,10 @@ func (a PodAlert) CustomResourceDefinition() *apiextensions.CustomResourceDefini
Labels: crdutils.Labels{
LabelsMap: map[string]string{"app": "searchlight"},
},
SpecDefinitionName: "github.com/appscode/searchlight/apis/monitoring/v1alpha1.PodAlert",
EnableValidation: true,
GetOpenAPIDefinitions: GetOpenAPIDefinitions,
SpecDefinitionName: "github.com/appscode/searchlight/apis/monitoring/v1alpha1.PodAlert",
EnableValidation: true,
GetOpenAPIDefinitions: GetOpenAPIDefinitions,
EnableStatusSubresource: EnableStatusSubresource,
})
}

Expand All @@ -70,9 +77,10 @@ func (a Incident) CustomResourceDefinition() *apiextensions.CustomResourceDefini
Labels: crdutils.Labels{
LabelsMap: map[string]string{"app": "searchlight"},
},
SpecDefinitionName: "github.com/appscode/searchlight/apis/monitoring/v1alpha1.Incident",
EnableValidation: true,
GetOpenAPIDefinitions: GetOpenAPIDefinitions,
SpecDefinitionName: "github.com/appscode/searchlight/apis/monitoring/v1alpha1.Incident",
EnableValidation: true,
GetOpenAPIDefinitions: GetOpenAPIDefinitions,
EnableStatusSubresource: EnableStatusSubresource,
})
}

Expand All @@ -88,8 +96,9 @@ func (a SearchlightPlugin) CustomResourceDefinition() *apiextensions.CustomResou
Labels: crdutils.Labels{
LabelsMap: map[string]string{"app": "searchlight"},
},
SpecDefinitionName: "github.com/appscode/searchlight/apis/monitoring/v1alpha1.SearchlightPlugin",
EnableValidation: true,
GetOpenAPIDefinitions: GetOpenAPIDefinitions,
SpecDefinitionName: "github.com/appscode/searchlight/apis/monitoring/v1alpha1.SearchlightPlugin",
EnableValidation: true,
GetOpenAPIDefinitions: GetOpenAPIDefinitions,
EnableStatusSubresource: EnableStatusSubresource,
})
}
1 change: 1 addition & 0 deletions chart/searchlight/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ The following table lists the configurable parameters of the Searchlight chart a
| `apiserver.versionPriority` | The ordering of this API inside of the group. | 15 |
| `apiserver.enableValidatingWebhook` | Enable validating webhooks for Searchlight CRDs | false |
| `apiserver.ca` | CA certificate used by main Kubernetes api server | `` |
| `apiserver.enableStatusSubresource` | If true, uses status sub resource for Searchlight crds | `false` |
| `enableAnalytics` | Send usage events to Google Analytics | `true` |

Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example:
Expand Down
1 change: 1 addition & 0 deletions chart/searchlight/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ spec:
- --audit-log-path=-
- --tls-cert-file=/var/serving-cert/tls.crt
- --tls-private-key-file=/var/serving-cert/tls.key
- --enable-status-subresource={{ .Values.apiserver.enableStatusSubresource }}
- --enable-analytics={{ .Values.enableAnalytics }}
ports:
- containerPort: 8443
Expand Down
2 changes: 2 additions & 0 deletions chart/searchlight/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ apiserver:
enableValidatingWebhook: false
# CA certificate used by main Kubernetes api server
ca:
# If true, uses status sub resource for Voyager crds.
enableStatusSubresource: false

# Send usage events to Google Analytics
enableAnalytics: true
1 change: 1 addition & 0 deletions docs/reference/searchlight/searchlight_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ searchlight run [flags]
--config-dir string Path to directory containing icinga2 config. This should be an emptyDir inside Kubernetes. (default "/srv")
--config-secret-name string Name of Kubernetes secret used to pass icinga credentials. (default "searchlight-operator")
--contention-profiling Enable lock contention profiling, if profiling is enabled
--enable-status-subresource If true, uses sub resource for Voyager crds.
--enable-swagger-ui Enables swagger ui on the apiserver at /swagger-ui
-h, --help help for run
--http2-max-streams-per-connection int The limit that the server gives to clients for the maximum number of streams in an HTTP/2 connection. Zero means to use golang's default. (default 1000)
Expand Down
14 changes: 12 additions & 2 deletions docs/setup/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ options:
--docker-registry docker registry used to pull searchlight images (default: appscode)
--image-pull-secret name of secret used to pull searchlight operator images
--run-on-master run searchlight operator on master
--enable-validating-webhook enable/disable validating webhooks for Searchlight CRD
--enable-validating-webhook enable/disable validating webhooks for Searchlight crds
--icinga-api-password password used by icinga2 api (if unset, a random password will be generated and used)
--enable-status-subresource If enabled, uses status sub resource for Searchlight crds
--enable-analytics send usage events to Google Analytics (default: true)
--uninstall uninstall searchlight
--purge purges searchlight crd objects and crds
Expand Down Expand Up @@ -105,6 +106,8 @@ $ curl -fsSL https://raw.githubusercontent.com/appscode/searchlight/7.0.0/hack/d
| bash -s -- --enable-admission-webhook [--rbac]
```

Searchlight 8.0.0 or later releases can use status sub resource for CustomResourceDefintions. This is enabled by default for Kubernetes 1.11.0 or later releases. To disable this feature, pass the `--enable-status-subresource=false` flag.

</div>
<div class="tab-pane fade" id="helm" role="tabpanel" aria-labelledby="helm-tab">

Expand All @@ -121,11 +124,18 @@ appscode/searchlight 7.0.0 7.0.0 Searchlight by AppsCode - Alerts for Kuber
# Kubernetes 1.8.x
$ helm install appscode/searchlight --name searchlight-operator --version 7.0.0 --namespace kube-system

# Kubernetes 1.9.0 or later
# Kubernetes 1.9.x - 1.10.x
$ helm install appscode/searchlight --name searchlight-operator --version 7.0.0 \
--namespace kube-system \
--set apiserver.ca="$(onessl get kube-ca)" \
--set apiserver.enableValidatingWebhook=true

# Kubernetes 1.11.0 or later
$ helm install appscode/searchlight --name searchlight-operator --version 7.0.0 \
--namespace kube-system \
--set apiserver.ca="$(onessl get kube-ca)" \
--set apiserver.enableValidatingWebhook=true \
--set apiserver.enableStatusSubresource=true
```

To install `onessl`, run the following commands:
Expand Down
1 change: 1 addition & 0 deletions hack/deploy/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ spec:
- --audit-log-path=-
- --tls-cert-file=/var/serving-cert/tls.crt
- --tls-private-key-file=/var/serving-cert/tls.key
- --enable-status-subresource=${SEARCHLIGHT_ENABLE_STATUS_SUBRESOURCE}
- --enable-analytics=${SEARCHLIGHT_ENABLE_ANALYTICS}
ports:
- containerPort: 8443
Expand Down
12 changes: 11 additions & 1 deletion hack/deploy/searchlight.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export SEARCHLIGHT_IMAGE_PULL_POLICY=IfNotPresent
export SEARCHLIGHT_ENABLE_ANALYTICS=true
export SEARCHLIGHT_UNINSTALL=0
export SEARCHLIGHT_PURGE=0
export SEARCHLIGHT_ENABLE_STATUS_SUBRESOURCE=false

export SCRIPT_LOCATION="curl -fsSL https://raw.githubusercontent.com/appscode/searchlight/7.0.0/"
if [[ "$APPSCODE_ENV" == "dev" || "$APPSCODE_ENV" == "test-concourse" ]]; then
Expand All @@ -122,6 +123,7 @@ fi

KUBE_APISERVER_VERSION=$(kubectl version -o=json | $ONESSL jsonpath '{.serverVersion.gitVersion}')
$ONESSL semver --check='<1.9.0' $KUBE_APISERVER_VERSION || { export SEARCHLIGHT_ENABLE_VALIDATING_WEBHOOK=true; }
$ONESSL semver --check='<1.11.0' $KUBE_APISERVER_VERSION || { export SEARCHLIGHT_ENABLE_STATUS_SUBRESOURCE=true; }

show_help() {
echo "searchlight.sh - install searchlight operator"
Expand All @@ -135,8 +137,9 @@ show_help() {
echo " --docker-registry docker registry used to pull searchlight images (default: appscode)"
echo " --image-pull-secret name of secret used to pull searchlight operator images"
echo " --run-on-master run searchlight operator on master"
echo " --enable-validating-webhook enable/disable validating webhooks for Searchlight CRDs"
echo " --enable-validating-webhook enable/disable validating webhooks for Searchlight crds"
echo " --icinga-api-password password used by icinga2 api (if unset, a random password will be generated and used)"
echo " --enable-status-subresource If enabled, uses status sub resource for Searchlight crds"
echo " --enable-analytics send usage events to Google Analytics (default: true)"
echo " --uninstall uninstall searchlight"
echo " --purge purges searchlight crd objects and crds"
Expand Down Expand Up @@ -178,6 +181,13 @@ while test $# -gt 0; do
fi
shift
;;
--enable-status-subresource*)
val=$(echo $1 | sed -e 's/^[^=]*=//g')
if [ "$val" = "false" ]; then
export SEARCHLIGHT_ENABLE_STATUS_SUBRESOURCE=false
fi
shift
;;
--enable-analytics*)
val=$(echo $1 | sed -e 's/^[^=]*=//g')
if [ "$val" = "false" ]; then
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmds/server/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/appscode/go/log"
hooks "github.com/appscode/kubernetes-webhook-util/admission/v1beta1"
"github.com/appscode/kutil/meta"
api "github.com/appscode/searchlight/apis/monitoring/v1alpha1"
cs "github.com/appscode/searchlight/client/clientset/versioned"
"github.com/appscode/searchlight/pkg/admission/plugin"
"github.com/appscode/searchlight/pkg/icinga"
Expand Down Expand Up @@ -46,6 +47,8 @@ func (s *OperatorOptions) AddGoFlags(fs *flag.FlagSet) {
fs.StringVar(&s.ConfigSecretName, "config-secret-name", s.ConfigSecretName, "Name of Kubernetes secret used to pass icinga credentials.")
fs.DurationVar(&s.ResyncPeriod, "resync-period", s.ResyncPeriod, "If non-zero, will re-list this often. Otherwise, re-list will be delayed aslong as possible (until the upstream source closes the watch or times out.")
fs.DurationVar(&s.IncidentTTL, "incident-ttl", s.IncidentTTL, "Garbage collects incidents older than this duration. Set to 0 to disable garbage collection.")

fs.BoolVar(&api.EnableStatusSubresource, "enable-status-subresource", api.EnableStatusSubresource, "If true, uses sub resource for Voyager crds.")
}

func (s *OperatorOptions) AddFlags(fs *pflag.FlagSet) {
Expand Down
19 changes: 17 additions & 2 deletions plugins/notifier/incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

api "github.com/appscode/searchlight/apis/monitoring/v1alpha1"
"github.com/appscode/searchlight/client/clientset/versioned/typed/monitoring/v1alpha1/util"
"github.com/appscode/searchlight/pkg/icinga"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -94,10 +95,24 @@ func (n *notifier) reconcileIncident() error {
incident.Status.Notifications = notifications

if api.AlertType(opts.notificationType) == api.NotificationRecovery {
incident.Labels[api.LabelKeyProblemRecovered] = "true"
_, _, err = util.PatchIncident(n.extClient, incident, func(in *api.Incident) *api.Incident {
if in.Labels == nil {
in.Labels = map[string]string{}
}
in.Labels[api.LabelKeyProblemRecovered] = "true"
return in
})
if err != nil {
return err
}
}

if _, err := n.extClient.Incidents(incident.Namespace).Update(incident); err != nil {
_, err = util.UpdateIncidentStatus(n.extClient, incident, func(in *api.IncidentStatus) *api.IncidentStatus {
in.LastNotificationType = api.AlertType(opts.notificationType)
in.Notifications = notifications
return in
}, api.EnableStatusSubresource)
if err != nil {
return err
}
} else {
Expand Down