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

Feature/istio quitquitquit 01 #124

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
41 changes: 37 additions & 4 deletions cmd/collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package main
import (
"flag"
"fmt"
"net/http"
"strings"
"time"

"github.com/SDA-SE/image-metadata-collector/internal/collector"
"github.com/SDA-SE/image-metadata-collector/internal/config"
Expand All @@ -17,14 +19,17 @@ import (
"github.com/spf13/viper"
)

const AppName = "collector"

const ShortDescription = "Collect images"
const LongDescription = `Image Metadata Collector is a tool that will scan
const (
AppName = "collector"
ShortDescription = "Collect images"
LongDescription = `Image Metadata Collector is a tool that will scan
'Namespace's,
and 'Pod's
for image and team information.
`
//istioQuitEndpoint = "http://localhost:15020/quitquitquit"
timeout = 5 * time.Second
)

func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
Expand Down Expand Up @@ -120,6 +125,9 @@ func newCommand() *cobra.Command {
c.PersistentFlags().StringVar(&cfg.CollectorImage.NamespaceFilter, "namespace-filter", "", "Default namespace filter to use")
c.PersistentFlags().StringVar(&cfg.CollectorImage.NamespaceFilterNegated, "negated_namespace_filter", "", "Default negated namespace filter to use")

// Add istioQuitEndpoint to the config structure
c.PersistentFlags().StringVar(&cfg.IstioQuitEndpoint, "istio-quit-endpoint", "http://localhost:15020/quitquitquit", "URL for the Istio sidecar quit endpoint")

c.PersistentFlags().AddGoFlagSet(flag.CommandLine)
return c
}
Expand Down Expand Up @@ -155,8 +163,26 @@ func bindFlags(cmd *cobra.Command, v *viper.Viper) {
})
}

// send a terminating QUITQUITQUIT signal to the Istio sidecar
func sendQuitQuitQuit(endpoint string) error {
client := &http.Client{Timeout: timeout}
resp, err := client.Post(endpoint, "text/plain", nil)
if err != nil {
return fmt.Errorf("failed to send QUITQUITQUIT to Istio sidecar: %v", err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("unexpected status code from Istio sidecar: %d", resp.StatusCode)
}

log.Info().Msg("Successfully sent QUITQUITQUIT to Istio sidecar")
return nil
}

// run starts the collector and metrics endpoint
func run(cfg *config.Config) {

k8client := kubeclient.NewClient(&cfg.KubeConfig)

storage, err := storage.NewStorage(&cfg.StorageConfig, cfg.Environment)
Expand Down Expand Up @@ -192,4 +218,11 @@ func run(cfg *config.Config) {
}
log.Info().Msg("Images collected and stored")
log.Debug().Interface("storage", storage).Msg("using storage")

// Before exiting, send QUITQUITQUIT to Istio sidecar
if err := sendQuitQuitQuit(cfg.IstioQuitEndpoint); err != nil {
log.Fatal().Err(err).Msg("Error sending QUITQUITQUIT to Istio sidecar")
}

log.Info().Msg("Collector finished")
}
2 changes: 2 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ type Config struct {
collector.RunConfig

Debug bool
// added for istioquitquitquit feature
IstioQuitEndpoint string
}
Loading