2019-03-14 14:23:47 -04:00
|
|
|
// Copyright 2018 Google LLC All Rights Reserved.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2020-10-23 16:47:34 -07:00
|
|
|
"flag"
|
2022-06-30 15:12:39 -04:00
|
|
|
"fmt"
|
2019-03-14 14:23:47 -04:00
|
|
|
"io/ioutil"
|
|
|
|
|
"log"
|
|
|
|
|
"os"
|
2020-09-04 17:32:26 +02:00
|
|
|
"os/signal"
|
2019-03-14 14:23:47 -04:00
|
|
|
"path/filepath"
|
2022-06-30 15:12:39 -04:00
|
|
|
"runtime"
|
2020-09-04 17:32:26 +02:00
|
|
|
"syscall"
|
2022-06-30 15:12:39 -04:00
|
|
|
"time"
|
2021-11-22 10:57:13 -08:00
|
|
|
|
|
|
|
|
// Give this an interesting import
|
|
|
|
|
_ "github.com/google/go-containerregistry/pkg/registry"
|
2019-03-14 14:23:47 -04:00
|
|
|
)
|
|
|
|
|
|
2020-10-23 16:47:34 -07:00
|
|
|
var (
|
2021-07-27 16:19:21 -04:00
|
|
|
f = flag.String("f", "kenobi", "File in kodata to print")
|
2020-10-23 16:47:34 -07:00
|
|
|
wait = flag.Bool("wait", true, "Whether to wait for SIGTERM")
|
|
|
|
|
)
|
|
|
|
|
|
2021-11-02 17:36:05 -04:00
|
|
|
// This is defined so we can test build-time variable setting using ldflags.
|
|
|
|
|
var version = "default"
|
|
|
|
|
|
2019-03-14 14:23:47 -04:00
|
|
|
func main() {
|
2020-10-23 16:47:34 -07:00
|
|
|
flag.Parse()
|
|
|
|
|
|
2021-11-02 17:36:05 -04:00
|
|
|
log.Println("version =", version)
|
|
|
|
|
|
2022-06-30 15:12:39 -04:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
|
// Go seems to not load location data from Windows, so timezone
|
|
|
|
|
// conversion fails unless tzdata is embedded in the Go program
|
|
|
|
|
// with the go build tag `timetzdata`. Since we want to test
|
|
|
|
|
// loading tzdata provided by the base image below, we'll just
|
|
|
|
|
// skip that for Windows here.
|
|
|
|
|
// See https://github.com/google/ko/issues/739
|
|
|
|
|
log.Println("skipping timezone conversion on Windows")
|
|
|
|
|
} else {
|
|
|
|
|
// Exercise timezone conversions, which demonstrates tzdata is provided
|
|
|
|
|
// by the base image.
|
|
|
|
|
now := time.Now()
|
|
|
|
|
loc, _ := time.LoadLocation("UTC")
|
|
|
|
|
fmt.Printf("UTC Time: %s\n", now.In(loc))
|
|
|
|
|
loc, _ = time.LoadLocation("America/New_York")
|
|
|
|
|
fmt.Printf("New York Time: %s\n", now.In(loc))
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-14 14:23:47 -04:00
|
|
|
dp := os.Getenv("KO_DATA_PATH")
|
2021-07-27 16:19:21 -04:00
|
|
|
file := filepath.Join(dp, *f)
|
2019-03-14 14:23:47 -04:00
|
|
|
bytes, err := ioutil.ReadFile(file)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("Error reading %q: %v", file, err)
|
|
|
|
|
}
|
2020-08-10 17:21:31 +02:00
|
|
|
log.Print(string(bytes))
|
2019-08-15 17:59:15 -07:00
|
|
|
|
2020-09-04 17:32:26 +02:00
|
|
|
// Cause the pod to "hang" to allow us to check for a readiness state.
|
2020-10-23 16:47:34 -07:00
|
|
|
if *wait {
|
|
|
|
|
sigs := make(chan os.Signal, 1)
|
|
|
|
|
signal.Notify(sigs, syscall.SIGTERM)
|
|
|
|
|
<-sigs
|
|
|
|
|
}
|
2019-03-14 14:23:47 -04:00
|
|
|
}
|