Skip to content

Commit

Permalink
Add external logging (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucklypriyansh-2 authored Oct 9, 2023
1 parent 364203b commit 4dfb2eb
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ func (p *SaladCloudProvider) createContainersObject(pod *corev1.Pod) []saladclie
if err == nil && gpuClasses != nil && len(gpuClasses) > 0 {
createContainer.Resources.SetGpuClasses(gpuClasses)
}
logging := p.getContainerLogging(pod)
if logging != nil {
createContainer.Logging.Set(logging)
}
creteContainersArray = append(creteContainersArray, *createContainer)
}
return creteContainersArray
Expand Down Expand Up @@ -522,3 +526,41 @@ func (p *SaladCloudProvider) getRestartPolicy(pod *corev1.Pod) (*saladclient.Con
}
return saladclient.NewContainerRestartPolicyFromValue(restartPolicy)
}

func (p *SaladCloudProvider) getContainerLogging(pod *corev1.Pod) *saladclient.ContainerLogging {
newRelicHost, hasRelicHost := pod.ObjectMeta.Annotations["salad.com/logging-new-relic-host"]
newRelicIngestionKey, hasRelicIngestionKey := pod.ObjectMeta.Annotations["salad.com/logging-new-relic-ingestion-key"]

splunkHost, hasSplunkHost := pod.ObjectMeta.Annotations["salad.com/logging-splunk-host"]
splunkToken, hasSplunkToken := pod.ObjectMeta.Annotations["salad.com/logging-splunk-token"]

tcpHost, hasTCPHost := pod.ObjectMeta.Annotations["salad.com/logging-tcp-host"]
tcpPort, hasTCPPort := pod.ObjectMeta.Annotations["salad.com/logging-tcp-port"]

if !hasRelicHost && !hasRelicIngestionKey && !hasSplunkHost && !hasSplunkToken && !hasTCPHost && !hasTCPPort {
return nil
}

containerLogging := saladclient.NewContainerLogging()

if hasRelicHost && hasRelicIngestionKey {
newRelic := saladclient.NewContainerLoggingNewRelic(newRelicHost, newRelicIngestionKey)
containerLogging.SetNewRelic(*newRelic)
}

if hasSplunkHost && hasSplunkToken {
newSplunk := saladclient.NewContainerLoggingSplunk(splunkHost, splunkToken)
containerLogging.SetSplunk(*newSplunk)
}

if hasTCPHost && hasTCPPort {
tcpPortInt, err := strconv.Atoi(tcpPort)
if err != nil {
log.G(context.Background()).Errorf("Failed to convert TCP port for logging")
} else {
newTCP := saladclient.NewContainerLoggingTcp(tcpHost, int32(tcpPortInt))
containerLogging.SetTcp(*newTCP)
}
}
return containerLogging
}

0 comments on commit 4dfb2eb

Please sign in to comment.