1
// Copyright Istio Authors
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
21
"istio.io/istio/pilot/cmd/pilot-agent/status/ready"
22
"istio.io/istio/pkg/file"
23
"istio.io/istio/pkg/istio-agent/grpcxds"
26
var _ ready.Prober = &probe{}
31
bootstrap *grpcxds.Bootstrap
34
// NewProbe returns a probe that checks if a valid bootstrap file can be loaded once.
35
// If that bootstrap file has a file_watcher cert provider, we also ensure those certs exist.
36
func NewProbe(bootstrapPath string) ready.Prober {
37
return &probe{bootstrapPath: bootstrapPath}
40
func (p *probe) Check() error {
42
if p.getBootstrap() == nil {
43
bootstrap, err := grpcxds.LoadBootstrap(p.bootstrapPath)
45
return fmt.Errorf("failed loading %s: %v", p.bootstrapPath, err)
47
p.setBootstrap(bootstrap)
49
if bootstrap := p.getBootstrap(); bootstrap != nil {
50
if fwp := bootstrap.FileWatcherProvider(); fwp != nil {
51
for _, path := range fwp.FilePaths() {
52
if !file.Exists(path) {
53
return fmt.Errorf("%s does not exist", path)
61
func (p *probe) getBootstrap() *grpcxds.Bootstrap {
67
func (p *probe) setBootstrap(bootstrap *grpcxds.Bootstrap) {
70
p.bootstrap = bootstrap